Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Instantiate object in for loop with array

$
0
0
So i am instantiating a GameObject which works just fine. Now i want to be able to save different instances of that GameObject and save those in an array and then display those via a for loop. For some reason My for loop isnt even executed. here is the Code: for(var i : int = 0; i <= eventsArray.length-1; i++){ print("i: "+i); DayDisplayInstance = Instantiate(DayDisplay, new Vector3(56.39999, -222.8), transform.rotation); DayDisplayInstance.transform.SetParent(startScreenPnl.transform, false); eventsArray.Add(DayDisplayInstance); DayDisplayInstance = eventsArray[i]; child = DayDisplayInstance.transform.GetChild(0).gameObject; myText = child.GetComponent.(); myText.text = "MO"; //Add variable instead of MO to make the event flexible } If i Instantiate and add to the array outside of the loop it workds but that ofc will not allow me to instanciate multiple times in that one function, that's why i want to do it in the for loop. My guess would be that the array is size 0 in the beginning and nothing is being added untill after the for loop. So the for loop says it starts at 0 and ends at array.length which since the array is empty is also 0. This results in the code in the for loop not being executed. How would i fix this? Any ideas? Anything would be much appreciated! Thanks in advance! . (the Vector3 is only for testing for now. My thought would be to make an array with vectors and then looping through that with i as well to display those GameObjects in the right position.

Viewing all articles
Browse latest Browse all 1875

Latest Images

Trending Articles



Latest Images