- Home /
GUI.button just isnt responding
Hey I've been searching up and down to try and figure out whats going wrong in this code for my GUI.Button but to no avail i still haven't been able to figure out why the button isn't working the problem is that when i click the button it doesn't have any effect here is my code
public bool play;
public GUISkin theSkin;
void Start(){
play = false;
}
void OnMouseUpAsButton(){
play = true;
}
void Update(){
if (play == true) {
Application.LoadLevel(1);
}
}
void OnGUI(){
GUI.skin = theSkin;
GUI.Button (new Rect (Screen.width / 2 - 140, Screen.height / 2 - 75, 300, 100), "PLAY");
GUI.Button(new Rect(Screen.width/2-140, Screen.height/2+30, 300, 100),"QUIT");
}
}
Answer by dsada · Aug 26, 2014 at 09:24 AM
Well you did not set any functionality for the buttons. You can do it like this:
if(GUI.Button (new Rect (Screen.width / 2 - 140, Screen.height / 2 - 75, 300, 100), "PLAY"))
{
play = true;
}
if(GUI.Button(new Rect(Screen.width/2-140, Screen.height/2+30, 300, 100),"QUIT"))
{
Application.Quit();
}
I hope you didnt expect that it will find out from the string that you want to play or quit :)
Thank you i reworked it and everything is running correctly now i appreciate it
Your answer
Follow this Question
Related Questions
Help with GUI clicking ??? 1 Answer
Move GUI elements. 0 Answers
Using GUI and check what button was pressed 1 Answer
GUI Button Disappearing 1 Answer
I have doubt please help me 2 Answers