[FIXED] OnTriggerStay being called by the object itself

I am facing a weird problem. I have a prefab which has a Box Trigger. I am instantiating 11 of these prefabs. I have a script attached to these prefabs that has nothing but the following code.


void OnTriggerStay(Collider collision )
{
     Debug.Log(collider.gameObject.ToString()+" Entered "+zoneID+" zone");
}

Console Output:
TriggerZone8 (UnityEngine.GameObject) Entered 8 zone

which is basically the same game object. Why is it calling it’s own OnTriggerStay function? Am I missing something?

Debug.Log(collider.gameObject.ToString()+" Entered “+zoneID+” zone");

in this line change collider.gameObject will only return the object itslef. you should be using collision.gameObject.

collider will access the component attacheted to it (it is more like using transform). The argument of OnTrigger function is actually collision.

Thanks vijayakumar.