- Home /
2d game end level with trigger and colission with trigger who to make a if condition
Hello everyone I need some help with my game. it´s a 2d game plataform so my problem is when the character make contact with the obstacles the character death but i want to put a flag in the scene to go to next level and this part doesn´t work.When the play make´s contact with the flag it´s the same to make contact with obstacle.
the part off code:
void OnTriggerEnter2D(){ StartCoroutine("DeathParticleDelay"); }
So i want to know if exist some if condition to make diference between the triggers the obstacle trigger and the flag trigger and i don´t know if i need to use tag,gameobject or another thing.
Thank you very much. It´s for unity 5
Answer by etopsirhc · Jul 01, 2015 at 12:37 PM
not quite sure how it's setup from the description. but here's some general info that might help.
the OnTriggerEnter2D function needs to have the parameter of (Collider2D parameterName) you will want to setup separate scripts for the obstacles and the goal flag
if your trigger area is on the player then you will want to tag the obstacles with obstacle and the goal with goal. then have the OnTriggerEnter2D check the flag by using the parameter.
void OnTriggerEnter2D (Collider2D other){
if(other.gameObject.tag == "goal"){
// do the victory stuff here
}
if(other.gameObject.tag == "obstacle"){
// do the kill player stuff here
}
}
Thank you very much etopsirhc , it´s exactly this What I need
I can solve my problem now.
Thank you and Have a nice day!