- Home /
Collide with other objects?
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.
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("Enemy")) {
Stats.Life -=1;
Player.enabled = false;
Light.enabled = false;
Invoke("LightsOn", Timer);
};
Answer by azzogat · Nov 30, 2010 at 09:52 AM
You've pretty much answered this question yourself:
Reference object A (the script carrier) on either B or C. Make B or C detect collisions/ triggers and send a message/ call a function from A when OnTriggerEnter.
If I'm not mistaken, this is one of the basics of gameController-centered game building, in which you have one central script that all other objects reference and call.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Script that will make car move normal 0 Answers
How to import the object from server to unity 2 Answers
How to make objects collide and move each other? 2 Answers
spawn point problem 1 Answer