- Home /
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.
Comment
Best Answer
Answer by DaveA · Apr 21, 2011 at 12:07 AM
It's the same, you omitted the parameter
function OnTriggerExit(hit : Collider)
{
if(hit.gameObject.tag == "Player")
{
}
}
Best Answer
Answer by Peter G · Apr 21, 2011 at 12:07 AM
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") {
}
}
Answer by Eric5h5 · Apr 21, 2011 at 12:09 AM
It's the same thing as OnTriggerEnter. Edit: cool, 3 answers at the same time. ;)