- Home /
how to push a Instantiate prefab to a array?
I figure and search about this problem but I just can't get a answer and decide to seek for help
I am trying to push a instantiate prefab to my array
This is my code:
Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
levelArray.Push(levelArray[levelInstanNum]);
but then I found out that the Instantiate object will be object(clone) that why it can't push in to the array
Any idea how I can make
levelArray.Push( Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity));
I know maybe is quite basic, sorry... I am quite new in programming and hope to seek some guide here
Thank you
how is the array declared? show the code you used to first create the array.
Answer by flamy · Dec 14, 2011 at 04:36 PM
var clone=Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
levelArray.Push(clone);
try this??
wat u actually did is adding the prefab to the array not the spawned gameObject..
if u r using c# change this a bit like
Object clone = Instantiate(levelArray[levelInstanNum],Vector3(levelInstanX,-2.5,0),Quaternion.identity);
levelArray.Push(clone);
i didnt try out the c# part though, it is jus a suggestion
Please click the check by the voting buttons to accept the answer :)