I am making a game like Temple Run and I do not want my player to die when he hits the sides what should I do?

I am making a game like Temple Run and I do not want my player to die when he hits the sides i only want him to die when he hits something infront of him.

Hi, So I am a little unaware of what you mean,

Are you asking what you should have it as? Or script.

Because if you want him to only die if he hits something in front of him,

Everything that you would add to the objects in front of him,

Just don’t apply it to the walls.

Good luck with your game though.

Something like this:

    void Death(){
    //Add what you want to happen when the player dies
}
    void OnCollisionEnter(Collider col){
           if(col.tag=="Obstacle"){
             Death();
           }
}

Note: You don’t have to even mention the walls, just tell unity what to do when you hit an obstacle. Also, make sure to add the tag, “Obstacle”, to the objects that are in your players way. The tag can be whatever you want, it doesn’t have to be,“Obstacle”.