- Home /
Question by
losingisfun · Dec 04, 2016 at 05:57 AM ·
instantiatearrayarray of gameobjects
how to set a GameObject variable to a GameObject[] variable ? - C#
Basically i'm storing a bunch of GameObjects that I want to spawn when the player goes to a new scene, but I can't instantiate them from an array.
I've tried this:
//declared at the beginning
public static GameObject[] companions = new GameObject[100];
//called in the Start() function
if (companionStatus [i] == 1) {
GameObject npc = GameObject [i];
npc = Instantiate (npc, pos, Quaternion.identity) as GameObject;
}
but it doesn't recognise the GameObjects in the array quite the same as a plain GameObject variable. Is it possible to store GameObjects into an array and then set individual GameObjects from them?
any help would be appreciated!
Comment
Best Answer
Answer by JedBeryll · Dec 04, 2016 at 06:27 AM
It's totally possible. If it's not working then you are assigning the values of the companions in a bad way.
GameObject npc = GameObject [i];
this line should be:
GameObject npc = companions [i];
oh whoops... I should have realised that. thanks XD !!!