I’m trying to assign an instantiated object to a variable to be used in other parts of the script:
GameObject go;
GameObject go = Instantiate(circlePrefabs*, NewPositions[randomIndex],*
Quaternion.indentity) as GameObject;
go = go.gameObject;
But it nevers assigns it, go
stays null and Unity even warns me that it will always have its default value. What’s going on here??
Edit: Renamed the variable, that seemed to fix it
Well, go is a GameObject, so I am not sure what you are trying to access whith “go.gameObject”
If you do
GameObject go = Instantiate(prefab, position, rotation);
you will get your GameObject in go, if you do Debug.Log(go.name); You should have the correct name.
Also, you don’t need to cast a Gameobject as a GameObject, not repear the variable type. You could simplify your code by doing something like this :
GameObject go = Instantiate(circlePrefabs*, NewPositions[randomIndex],*
Quaternion.indentity);