- Home /
Put objects in a row and give them specific positions
how can i put collided objects in a row? so that the script tells the first collided object it is the first, the second it is the second, the third it is the third and so on. i want then tell every objects to go to a specific position so that the first collided object will always go the the same position, no matter which of all object is the first. then the second collided will go to its position and so on. could someone please help me? thank you!!
Answer by Loius · Jun 29, 2012 at 02:37 PM
[LineupController.js]
private var objects : List.<GameObject>;
var positions : Vector3[];
function Start() {
objects = new List.<GameObject>();
}
function Collided( object : GameObject ) {
objects.Add( object );
}
function LineUp() {
for ( var ix : int = 0; ix < objects.Count; ix++ ) {
objects[ix].transform.position = position[ix];
}
}
function Clear() { objects = new List.<GameObject>(); }
Then set up your positions in the inspector and call the functions as appropriate.
Your answer
Follow this Question
Related Questions
Editing a jagged array? 1 Answer
Checking if a position is occupied in 2D? 1 Answer
Fill an Array with GameObjects from another script 1 Answer
Model Animation with an Array 1 Answer