I have been struggling with this fairly basic issue: To make a game over menu appear upon death, as well as making it so a menu is also displayed upon winning.
I am making a 3D game in Unity, where you, the player, must control a sphere with the basic controls: w,a,s,d/up,down,left,right. It is a game where you must “drive” the ball and pass a broad variety of obstacles to ultimately win the game. I have already implemented the Main Menu, Pause Menu and the actual game overall. I just need to figure out how to make it so the player can actually lose and win the game. The 2 most important aspects of a game. To lose. To win. Unfortunately, I have not a single clue on how I can make such. The player is on a platform, as are the obstacles etc. I have made in my game a bridge you must cross over, on which below it is nothing. So, if you slide off the 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. On the other hand, there is only one way to win the game. You must control your ball, passing through obstacles and lead the ball to fall into a box, on which if the ball is within it, you win. I basically have no clue how to make any of this a reality. Not one single clue. If possible, I would be delighted if anyone could develop a script for both for me. Java Script or C#, doesn’t matter. If you can assist me in anyway, please do. I am going to release this game for the PC, on Steam soon and if possible.
the easiest way to make the game over part is to create a cube,make it transparent by unchecking it’s mesh renderer(don’t do this until after you’ve finished otherwise things can get confusing), and resize it so if your sphere falls off the bridge it’s guaranteed that the sphere will collide with the cube.Now make two scenes.One for game over and one for winner. And , assuming you’ve already made your winner’s box, here’s the javascript code:
#pragma strict //It's good to put this at the top of each javascript script
function OnCollisionEnter(theCollision : Collision) { //Unity's built in collision function
if(theCollision.gameObject.name == "Whatever you called that cube I asked you to make") { //if the collision is called Whatever you called that cube I asked you to make
Application.LoadLevel("Whatever your game over scene is called"); //this loads your game over scene. Make sure you put that scene in the build settings
}
if(theCollision.gameObject.name == "Whatever you called your box") { //I'll let you figure this out :)
Application.LoadLevel("Whatever your winner scene is called"); //You get the idea, but be sure to put your winner scene in the build settings.
}
}
What I would do is put a script on the ball that triggers a lose event if its y value becomes to low, because it fell. Then I would also put invisible triggerboxes around any deadly obstacles as well as the “win zone”.