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.

3 Answers

3

It's the same, you omitted the parameter

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

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") {
    }
}

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