- Home /
Creating Object Arrays
at the moment i am testing arrays for a turn based style game but i cant get the hang of object arrays, how do you get an object into an array iv made some objects in my hierarchy but i can seem to get them into arrays do they need to be prefabs to go into arrays so far iv got this
var plates : GameObject[];
function OnGUI(){
if(GUI.Button(Rect(10,10,100,50),"Click")){ Debug.Log("next step");
}
plates = [X1,X2];
}
What are X1 and X2? What are you trying to accomplish in this code.
Answer by DaveA · Mar 19, 2012 at 11:38 PM
You should read this: http://unity3d.com/support/documentation/ScriptReference/Array.html
I still don't undestand why you spammed this post with an inane answer...
Answer by AdvsNoob · May 13, 2014 at 11:35 PM
You need to add the values to the array, im a bit rusty on Javascript so I will try my best to show you.
//Declare the array and make it a float
var aFloat: float[];
function Start () {
//Initialize it
aFloat = new float[5];
}
function OnGUI(){
if(GUI.Button(Rect(10,10,100,50),"Click")){ Debug.Log("next step");
}
//Add to the 1st slot of the float (Which is always 0) so in this case this float
//will be from 0-4.
aFloat[0] = 1.2;
}
If you explain what you are trying to do and what X1, X2 are I can give you a much better example.