- Home /
Access to components and their variables in Array.
I've 8 ai cars with my own ai script. I'm having some troubles with positions and stats. Each car has their own float values named position. I need to collect these values in to one array and sort them.
var aiplayers : GameObject[];
aiplayers = GameObject.FindGameObjectsWithTag("AI");
var aiscripts : Component[];
aiscripts = aiplayers.GetComponents.<AICarScript>();
I can access all AICarScripts in scene, but now how can i access my public position value in [ALL] AICarScripts with one command? And how can i sort them in GUI with their gameObject names?
Accessing the variable would look like..
aiscripts.position
assu$$anonymous$$g that the AICarScript has such a variable..
And doing that for all elements of "aiscripts" would look like..
for(var ai:AICarScript in aiscripts)
ai.position ....
Your answer
Follow this Question
Related Questions
Problem with Accessing Variables from Other Scripts in c#. 1 Answer
comparing variables of gameobjects in an array 2 Answers
access unity 5 carcontroller variables with script 0 Answers
How do I access a script from a class inside a script. 1 Answer
How do I save an array of all different variables? 0 Answers