Hi,I got a problem with the “NullReferenceException” error form this code:
function A(){
var temp = new GameObject();
temp.name = "red";
colorArray[0] = temp;
}
function B(){
var name : String = colorArray[0].ToString();
Debug.Log(name); // it shows "red", no problem.
// and I confirm the "red" GameObject is on the Hierarchy.
var obj : GameObject = GameObject.Find(name);
Debug.Log(obj); // **it shows "null", it really confuse me**
Destroy(obj); // error message from this line
}
In game mode, I actually see the “red” instance on the Hierarchy but why the function “GameObject.Find” doesn’t work?