- Home /
How to make an array of GameObjects that stores their transforms?
How could I do this or when I call the function that needs this should I just use gameobjectArray.transform? What do you think?
Just use a Transform array if that's what you're working with mostly anyway. Otherwise make a 2nd array for your transforms if you don't want to do the "objArray.transform" thing.
The script needs to add gameobjects to the array that I have to it whenever I click the mouse button on a certain event. How could I add get a transform of a gameobject and than add it using .add to the array?
Answer by getyour411 · May 09, 2014 at 02:40 AM
Every GameObject has a transform so
public GameObject[] myArray;
then you capture a GameObject with your click and increase the array index and add
myArray[index+1] = clickedGameObject;
you can then access it
myArray[index].transform
don't cut and paste that, just my thoughts, search Unity for many examples of actual code snippets.