x


Do a collider only with certain taged objects

Hi, I have done a little rutine to detect players that collide on a certain area, but I have the problem that monsters can enter too... So I want only to detect objects with the tag player:

Here is my code:

 function OnTriggerEnter(Player : Collider) {
     if (numeroDePersonasEnElTanque==0){
         isPlayerVisible = true;
         playerTriggered=Player.gameObject.transform;
     }
     else{
         isPlayerVisible  = false;
         playerTriggered=null;
     }
 }

What function should I use to solve it?

more ▼

asked May 28, 2011 at 02:06 PM

Infinity gravatar image

Infinity
141 105 78 83

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

2 answers: sort voted first

if (player.gameObject.tag == "Player") {...} or use CompateTag()

more ▼

answered May 28, 2011 at 02:10 PM

Joshua gravatar image

Joshua
7k 47 50 105

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

You can use GameObject.CompareTag - look at:

http://unity3d.com/support/documentation/ScriptReference/GameObject.CompareTag.html

That's the example they show:

 // Immediate death trigger.
 // Destroys any colliders that enter the trigger, if they are tagged player.
 function OnTriggerEnter (other : Collider) {
 if (other.gameObject.CompareTag ("Player")) {
 Destroy (other.gameObject);
 }
 }

more ▼

answered May 28, 2011 at 02:14 PM

aldonaletto gravatar image

aldonaletto
58.2k 34 106 316

(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:

x5046
x4379
x1814
x1410
x578

asked: May 28, 2011 at 02:06 PM

Seen: 2615 times

Last Updated: May 28, 2011 at 02:14 PM