x


Using Tags with OnTriggerExit

If anyone can tell me how to use a tag when calling for an On Trigger Exit that would be great. I know how to use tags for an On Trigger Enter. This is what I mean.

function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
}
}

I am not sure on how to chack if the gameObject with the tag "Player" is exiting.

function OnTriggerExit(){
// how do i check if the player is leaving
}

So if anyone knows how to check the tags of a gameObject incased in a OnTriggerExit function, it would be really helpful.

more ▼

asked Apr 20 '11 at 11:30 PM

Alex 9 gravatar image

Alex 9
79 19 18 20

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

3 answers: sort oldest

The same way you check when it enters. Just change "Enter" to "Exit".

//OnTriggerExit has the same optional parameter as OnTriggerEnter()
function OnTriggerExit(col : Collider){
// how do i check if the player is leaving
    if(col.tag == "SomeTag") {
    }
}
more ▼

answered Apr 21 '11 at 12:07 AM

Peter G gravatar image

Peter G
15k 16 44 136

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

It's the same, you omitted the parameter

function OnTriggerExit(hit : Collider)
{
  if(hit.gameObject.tag == "Player")
  {
  }
}
more ▼

answered Apr 21 '11 at 12:07 AM

DaveA gravatar image

DaveA
26.4k 151 171 256

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

It's the same thing as OnTriggerEnter. Edit: cool, 3 answers at the same time. ;)

more ▼

answered Apr 21 '11 at 12:09 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

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

x1089
x980
x801
x58
x57

asked: Apr 20 '11 at 11:30 PM

Seen: 1865 times

Last Updated: Apr 20 '11 at 11:30 PM