- Home /
In-Game GUI buttons don't work
I am writing a C# code for a game i am making and it is for a In-Game GUI the aesthetics work fine but the buttons aren't doing nuthin.
using UnityEngine;
using System.Collections;
public class InGameGUI : MonoBehaviour
{
public string siteAdress;
public bool mainMenu = false;
public bool isQuit = false;
public bool doWindow0 = true;
public bool doWindow1 = true;
private bool isPaused = false;
Texture2D resumeTexture;
void Update()
{
if(Input.GetButtonDown("Pause") && !isPaused)
{
print("Paused");
Time.timeScale = 0.0f;
isPaused = true;
GetComponent<MouseLook>().enabled = false;
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = false;
}
else if(Input.GetButtonDown("Pause") && isPaused)
{
print("Unpuased");
Time.timeScale = 1.0f;
isPaused = false;
GetComponent<MouseLook>().enabled = true;
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = true;
}
}
void DoWindow0(int windowID)
{
if(isPaused == true)
{
GUI.Button(new Rect(10, 550, 280, 20), "Quit");
}
if(isPaused == true)
{
GUI.Button(new Rect(10, 520, 280, 20), "Back To Main");
}
}
void DoMyWindow(int windowID)
{
if(GUI.Button(new Rect(10, 550, 280, 20), "Quit"))
{
isQuit = true;
}
if(GUI.Button(new Rect(10, 520, 280, 20), "Back to Main"))
{
mainMenu = true;
}
}
void OnMouseDown()
{
if(isQuit)
{
Application.Quit();
}
if(mainMenu)
{
Application.LoadLevel("Main Menu");
}
}
void OnGUI()
{
if(isPaused == true)
{
if(doWindow0)
{
GUI.Window(0, new Rect(0, 0, 300, 595), DoWindow0, " Main Menu");
}
}
}
}
Comment
Answer by gbelini · Jan 09, 2013 at 11:18 AM
Please, try this code and let me know if this work, because this works for me
using UnityEngine;
using System.Collections;
public class InGameGUI : MonoBehaviour
{
public string siteAdress;
public bool mainMenu = false;
public bool isQuit = false;
public bool doWindow0 = true;
public bool doWindow1 = true;
private bool isPaused = false;
Texture2D resumeTexture;
void Update()
{
if(Input.GetButtonDown("Pause") && !isPaused)
{
print("Paused");
Time.timeScale = 0.0f;
isPaused = true;
GetComponent<MouseLook>().enabled = false;
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = false;
}
else if(Input.GetButtonDown("Pause") && isPaused)
{
print("Unpuased");
Time.timeScale = 1.0f;
isPaused = false;
GetComponent<MouseLook>().enabled = true;
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = true;
}
}
void DoWindow0(int windowID)
{
if(isPaused == true)
{
GUI.Button(new Rect(10, 550, 280, 20), "Quit");
}
if(isPaused == true)
{
GUI.Button(new Rect(10, 520, 280, 20), "Back To Main");
}
}
void DoMyWindow(int windowID)
{
if(GUI.Button(new Rect(10, 550, 280, 20), "Quit"))
{
Debug.Log("Quit Button Click");
//Do not work on editor
Application.Quit();
}
if(GUI.Button(new Rect(10, 520, 280, 20), "Back to Main"))
{
Debug.Log("Menu button click");
Application.LoadLevel("Menu");
}
}
void OnMouseDown()
{
if(isQuit)
{
Application.Quit();
}
if(mainMenu)
{
Application.LoadLevel("Main Menu");
}
}
Rect wRect = new Rect(0,0,300,595);
void OnGUI()
{
if(isPaused == true)
{
wRect = GUI.Window(0, wRect, DoWindow, " Main Menu");
}
}
}