1
我在Unity中制作了一个文字游戏,其中有很多GameObjects。每个GameObject名称是从A到Z的一个字母。unity3d消失Gameobject
当我单击该对象时,该字母出现在屏幕上。当我写了一个字时,它会将它与字典进行比较,看它是否正确。我想,当我从这些字母中选出一个正确的单词并单击该按钮时,GameObject就会包含这些字母,这些字母就是我所做的单词消失的。
下面是代码:
internal void ReadStudent(string filetoread,string tableName, string itemToSelect, string wCol, string wPar, string wValue){
//jsScript = Camera.main.GetComponent<chk1>();
string connection = "Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" + filetoread;
Debug.Log(connection);
string sqlQuery = "SELECT word FROM "+ tableName + " WHERE " + wCol + " " + wPar + " '" + wValue + "'";
OdbcConnection con = new OdbcConnection(connection);
OdbcCommand cmd = new OdbcCommand(sqlQuery,con);
DataTable dt = new DataTable("dic");
try{
con.Open();
OdbcDataReader reader = cmd.ExecuteReader();
dt.Load(reader);
reader.Close();
con.Close();
}
catch (Exception ex){
//text = dt.Rows[3][1].ToString();
Debug.Log(ex.ToString());
}
finally{
if (con.State!=ConnectionState.Closed){
con.Close();
}
con.Dispose();
}
if (dt.Rows.Count>0){
text = dt.Rows[0]["word"].ToString();
Debug.Log(text);
Debug.Log (wValue);
Debug.Log ("Correct");
for(int i=0; i<=wValue.Length;i++){
Debug.Log ("Enter");
if(wValue[i]==gameObject.name[i]){
Debug.Log ("Enter");
gameObject.SetActive (false);
}
}
}
}
['GameObject.Destroy(游戏对象)'](http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html)应做的伎俩。 –
在我的游戏中,gameObject正在运行时创建名称,如A(克隆)GameObject.Destroy。(gameObject)不适用于它。我怎么能得到在运行时创建的gameObject – zahra
我的意思是说,gameObject必须是对你想销毁的对象的引用。当你创建这个对象时,你应该在那个时候引用它,也许你可以将它们存储在一个列表中,然后通过并在以后删除它们?有点取决于如何布置所有东西 –