- Home /
loop with array system
i was searching for a way to find all the objects with name "example" and put them in a list of arrays
for example i have 20 objects that has the same name i wanna list them automatically in the arrays by for loop so i can check which one was collided with my object and detect it without many lines of code
how did you set the name of these objects and how you want to check collision?
Because the OnCollisionEnter method has the Collision parameter:
C#:
void OnCollisionEnter(Collision collision) {
// now you have the object that collided with the current object in collision variable
if(collision.gameObject.tag == "myTag")
// DoSomething();
}
js:
function OnCollisionEnter(collision : Collision) {
// now you have the object that collided with the current object in the collision variable
if(collision.gameObject.tag == "myTag")
// DoSomething();
}
If that's just collision, use OnCollisionEnter() callback : http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
it isn't the collisions only that i want , the idea was to make an array system with something like tag tag1 tag11 tag111 etc
or
tag1 tag2 tag3 etc by for loop so i wanna check how many tags are out their then check write them by the closest to him then write it in the array so it will be updated by the distance he go after
thanx for trying