- Home /
arraylist to array
i am trying to assign an array named scrollobjects which is of gameobject[] type, the items of arraylist. here is the code.::
for(i=0;i<numberOfPlanes;i++)
{
GameObject pup = Instantiate(popUpPlane,new Vector3(i*nextPlaneXoffest,-2.66f,0),Quaternion.Euler(-90,0,0)) as GameObject;
pup.GetComponent<PopUpButtonScript>().initialize(15);
instantiatedPlane.Add(pup);
}
Camera.mainCamera.GetComponent<ScrollList>().scrollObjects=(GameObject[])instantiatedPlane.ToArray(typeof (GameObject));
here instantiated plane is a arraylist and scrollobjects is an array of gameobjects.
when i am doing debug.log(scrollObjects.length) it is returning 0;
meaning no object of arraylist is being assigned to array scollObject...
why is this so..?? how to do so..??
any help would be appriciated..!! thanks
Have you tried this
Camera.mainCamera.GetComponent().scrollObjects = instantiatedPlane.ToArray();
Answer by ThePunisher · Oct 05, 2012 at 04:28 PM
Try this:
for(i=0;i<numberOfPlanes;i++)
{
GameObject pup = Instantiate(popUpPlane,new Vector3(i*nextPlaneXoffest,-2.66f,0),Quaternion.Euler(-90,0,0)) as GameObject;
pup.GetComponent<PopUpButtonScript>().initialize(15);
instantiatedPlane.Add(pup);
}
Camera.mainCamera.GetComponent<ScrollList>().scrollObjects = instantiatedPlane.ToArray() as GameObject[];
Sundar almost had it, he was just missing the type cast at the end. If your debug check still outputs 0 then that means your for loop isn't getting executed. Put a debug statement in there just verify that too.
Your answer
Follow this Question
Related Questions
get int based on 3 ints 0 Answers
Help with for loop and arrays 3 Answers
How to acces the value of List of arrays 0 Answers
Array sub elements setup question 1 Answer
How to Clone Array1 into Array2 in Unity? Using JavaScript. 0 Answers