After my player is supposed to die, the camera switches and a GUI button is supposed to show up that quits the game. Here is my code:
function OnGUI()
{
//When Player Dies
if(health <= 0)
{
GUI.Box (Rect (10,10,100,90), "Quit Game");
//If the button is clicked, application quits.
if(GUI.Button (Rect (10,10,100,90), "Quit Game"))
{
Application.Quit();
}
}
}
Please help, if you need to know anything else, please ask.
Sebiu
2
If you destroy your player when the health reaches zero, the script attached to it is destroyed too, so it can’t execute the istructions in OnGUI.
Try moving the code in another script that is not destroyed with the player, such as the camera.
rezki
3
use directly the GUI.Button you don’t need a GUI.Box.
function OnGUI()
{
//When Player Dies
if(health <= 0)
{
//If the button is clicked, application quits.
if(GUI.Button (Rect (10,10,100,90), "Quit Game"))
{
Application.Quit();
}
}
}