- Home /
Making Game Over And Win Screen
Hello,
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.
Best regards,
fcc32
BU$$anonymous$$P! I still am in need of full assistance! Help! Anyone? Please and thank you!
Answer by FrederikK · Dec 27, 2015 at 11:51 AM
What you need are events and collider triggers.
https://unity3d.com/learn/tutorials/modules/intermediate/scripting/events
https://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers
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".
Sorry, I am a complete novice in Unity. Could you provide these scripts if possible? Thank you for your response.
we don't "provide" scripts, we help with problems.
Answer by Developer1212 · Jan 10, 2016 at 05:41 PM
Hello, I've made a game similar to this.
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.
}
}
Also, I wouldn't rush into this kind of stuff. Watch some tutorials. I would recommend Brackeys or my tech tutorials website www.technologywithmax.wordpress.com
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Problem Javascript to C# 3 Answers
dealing with gameObject formations 1 Answer