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 77 81

(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
6.9k 46 46 100

(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
56.8k 31 77 291

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

x4684
x4019
x1651
x1289
x535

asked: May 28, 2011 at 02:06 PM

Seen: 2441 times

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