Hello. I know how to make it so that a function happens when the object that a collision script (like the one below) is attached to collides with another object, but is there a way to make a script that references another object for both objects? For example, the script is attached to object A and it says something like "When object B enters the trigger of an object with the tag "C" object B = destroyed)? Thanks. Code (csharp): function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Enemy")) { Stats.Life -=1; Player.enabled = false; Light.enabled = false; Invoke("LightsOn", Timer); };
You can't "listen" for collisions between two other objects but you can script one of the colliding objects to send a message to the third object when the collision happens.
Sorry for the necro. The method I used here was to simply create a class Collision variable and inside your OnCollisionEnter(Collision col) routine make that variable = col. Easy way to expose the information.