- Home /
 
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?
Answer by Joshua · May 28, 2011 at 02:10 PM
if (player.gameObject.tag == "Player") {...} or use CompateTag()
Answer by aldonaletto · May 28, 2011 at 02:14 PM
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);
 }
 }
 
              Your answer
 
             Follow this Question
Related Questions
Tag Player in VRTK 1 Answer
Trigger respawn after collision? 3 Answers
Action activates trigger. 1 Answer
Player detecting collision when crouching 1 Answer
how to make triger fireball not to pass through spesific objects 2 Answers