- Home /
Making Game Over
Hello =) ive found this script for game over: using UnityEngine;
/// /// Start or quit the game /// public class GameOverScript : MonoBehaviour { void OnGUI() { const int buttonWidth = 120; const int buttonHeight = 60;
if (
GUI.Button(
// Center in X, 1/3 of the height in Y
new Rect(
Screen.width / 2 - (buttonWidth / 2),
(1 * Screen.height / 3) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"Retry!"
)
)
{
// Reload the level
Application.LoadLevel("Game");
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 2 - (buttonWidth / 2),
(2 * Screen.height / 3) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"Back to menu"
)
)
{
// Reload the level
Application.LoadLevel("Menu");
}
}
}
Question 1 :but the Buttons dont goes invisible while i Play the game how to i make that? Question 2 :what Need i write to script to make it gameover when Player falls down :P thank you!
Answer by drudiverse · Aug 15, 2014 at 11:35 AM
that code is complicated, best to go the unity reference page (it is brilliant)
copy and paste this code, take out the texture if you want its easier, use "string" only:
http://docs.unity3d.com/ScriptReference/GUI.Button.html if you learn copy paste that things, then you will learn unity, promised:
do this:
void function OnGui (){
IF (player.transform.eulerAngles.z <= 45 )//find something like that mean he fell over
{
ongui.button (screen pisition, button size , "retry string"){reload level code}
ongui.button (screen position, button size , "menu string"){menu code}
}
}
this is the function your call if button is pressed: to reload level Application.LoadLevel("your level name");
I've paste youre script but gave me parsing error: Assets/Scripts/GameOverScript.cs(1,19): error CS8025: Parsing error
And the Buttons appears only when i die ? by my script appears it always :P
thank you, muhammed
Your answer
Follow this Question
Related Questions
How to display a "Game Over" after death? 2 Answers
How do I add a game over screen on my Javascript? 0 Answers
GameOver Scene 1 Answer
C# Script help with 2D sidescroller 1 Answer
Making Game Over And Win Screen 3 Answers