- Home /
Adding a collider to array
I need to add colliders of the function OnTriggerEnter to the enemiesinrange array, this is my current code:
var enemiesinrange = new Array();
var objects : int = 0; //used to count the enemies in range, not really related.
function OnTriggerEnter (other : Collider) {
objects++;
enemiesinrange.Add(Collider);
print(other.BasicEnemy.age);
print(enemiesinrange[0].BasicEnemy.age);
}
Its supposed to add the "other" collider to my enemiesinrange array. It returns an error "Object reference not set to an instance of an object" on the following line:
**enemiesinrange.Add(Collider);**
Damn, arrays are problematic.
Answer by Gnometech · May 20, 2014 at 12:44 PM
Try
enemiesinrange.Add(other);
instead of
enemiesinrange.Add(Collider);
enemiesinrange.Add(other);
is giving me the same error ("Object reference not set to an instance of an object").
Edit: I changed it to list and it kind of works now.
Your answer
Follow this Question
Related Questions
How to add colliders to an array, and pick the oldest one? 1 Answer
Can't click gameobject when over another trigger? 1 Answer
character controller only triggers colliders on its sides 1 Answer
Collider Activate Trigger Animation 0 Answers
OnTriggerEnter not being called with multiple colliders 1 Answer