# Making a Fall Trigger Game Over

I have been struggling with this fairly basic issue: To make a game over menu appear upon death.

I am making a 3D game in Unity, where you, the player, must control a sphere with the basic controls: W, A, S, D and , , , . It is a game where you must "drive" the ball and pass a broad variety of obstacles, where you must lead the ball to fall into a confined box where, if within it, you ultimately win the game.

I have already implemented the Main Menu, Pause Menu and the fundamental gameplay components. I just need to figure out how to make it so the player can actually lose the game. The most important aspect of a game.

I have not a clue on how I can make this.

The player is on a platform, as are the obstacles etc. I have made in my game 2 bridges you must cross over, on which below it is nothing. So, if you slide off a bridge, you will basically die, as there is nowhere else to go upon falling. I want to make it so that when you fall from the actual platform, or the map, falling into the "abyss", you will die, on which I would like a game over screen to appear, there being a play again button, and a button that will quit the game.

I basically have no clue how to make any of this a reality. If possible, I would be delighted if anyone could develop a script for this. Java Script or C#, doesn't matter. If you can assist me in anyway, please do.

• Considering that you already have a main menu and a pause menu, what prevents you from using the same technique to create a game over menu? Or is your problem just detecting that the lose-condition (falling down the bridge) occured? – Philipp Jan 2 '16 at 17:07
• If you post the code for the player and the menu implementations you currently have, it will be easier to point you in the correct direction. – Mattias Jan 2 '16 at 17:45
• I do not require the aid to simply design a Game Over menu, rather I need to make it so that the game detects that the player had fell off the platform, on which a Game Over menu would appear. What Philipp said. – An Anonymous Ignoramus Jan 3 '16 at 13:41
• For my player, I basically just use the code and components that is defaulted to the Rollerball prefab. I just replaced the actual Rollerball model with a sphere. The only differences between the prefab and my player is the speed, move power and max angular velocity both being 150, and scale, 5 on each axis. – An Anonymous Ignoramus Jan 3 '16 at 13:49
• For my Main Menu, I just followed Brackey's tutorials: youtube.com/watch?v=1z5aAK0rN-4 for designing the Main Menu and youtube.com/watch?v=JIlKuZffmwE for coding it. I just touched up the actual appearance of his Main Menu. – An Anonymous Ignoramus Jan 3 '16 at 13:51

According to your comments you want to detect when the player-character leaves the playing area and do something.

This is easily done by creating a new game object with a large BoxCollider representing the play-area. Set the "Is Trigger" to on, so it doesn't have any physical interaction and instead is completely scripted.

Then attach a new script to that game object and implement the OnTriggerExit function. This function will be called whenever an object leaves the BoxCollider attached to this game object. Remember that this applies to all game objects which have Colliders, not just to the player, so have your implementation check if it's actually the player before showing the game over screen.

Alternative solution: Instead of just one "life" box collider which kills the player when they leave, you can also have one or more "death" box colliders which kills the player when they enter. You can do that by implementing OnTriggerEnter instead. But when you place such a collider below your play area, make sure it is large enough that the players can't miss it. Keep in mind that games with rigid-body physics can become quite unpredictable and might launch objects out of the playing area with very high speeds.