Ok I have been working on this for a few hours now. I have played around with my code and got the GUI window and the Yes button to not show while I play game. Is this the best code setup for what I am trying to do? Will the window and button always be there taking up cpu with this code set up?
using UnityEngine;
using System.Collections;
public class ExitGame : MonoBehaviour {
// this is the window for the exit yes button
public bool ExitGameWindow = false;
// This is the Exit Yes button
public bool ButtonYes = false;
// Use this for initialization
void Start () {
Screen.showCursor = false;
}
// Update is called once per frame
void Update () {
// This will show the mouse cursor when you hit Escape key and open the ExitGameWindow.
if (Input.GetKey (KeyCode.Escape)) {
ExitGameWindow = true;
ButtonYes = true;
Screen.showCursor = true;
}
}
// Void OnGUI() is the function for your Graphic user Interface (GUI)
void OnGUI() {
// Make a backgroud for the button.
// This type of code will never allow the box with the buttons in it to change postion on screen no matter what screen size.
// As of now the if(ExitGameWindow) makes it so when you start game this window does not show.
if (ExitGameWindow) {
GUI.Box (new Rect (Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 200), "Exit To Main Menu?");
}
// Make a button that can be clicked on.
// Debug.Log() creates text in your console.
// Application.LoadLevel(); Takes you to what ever scene that you tell it to. scene number goes in () after LoadLevel.
// if(ButtonYes) This will make it to where the yes button will not show when game is played.
if (ButtonYes) {
if (GUI.Button (new Rect (Screen.width / 2 -70, Screen.height / 2 -120, 150, 50), "Yes"))
// Takes you back to the Main Menu.
Application.LoadLevel(0);
Debug.Log ("Going Back To Main Menu");
}
}
}
Next thing I want to learn how to do is when this code happens I want the player to not move when I try and click the button that shows up and I want the game to pause. These two functions might do the same, but I have not started reading the Time.timescale scripts yet.