x


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);
      }; 
more ▼

asked Nov 30 '10 at 03:59 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Nov 30 '10 at 09:52 AM

azzogat gravatar image

azzogat
918 3 16

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5089
x142
x45

asked: Nov 30 '10 at 03:59 AM

Seen: 839 times

Last Updated: Nov 30 '10 at 03:59 AM