I have a GUI Button to unlock a level. If my score is greater than 50, unlock a level. My score is not greater than 50, show a gui box and a text.
My code is:
if(GUI.Button(new Rect(0,0,50,50),"unlock")) {
if (score>=50) { /*sth*/ }
else{ GUI.Box(Rect(50,50,50,50,"not enough score")) }
But it doesn’t work. I can’t take any response in else statement.
And also these are in OnGUI function.
It’s work, but only one frame, when you press button. For example, your box showing in 2second after press button. See simple example below:
private float boxTime = 0.0f;
void Update() {
//Create simple timer for boxTime and show our box
if (boxTime > 0) {
boxTime = boxTime - Time.deltaTime;
}
}
void OnGUI() {
if(GUI.Button(new Rect(0,0,50,50),"unlock")) {
if (score>=50) {
/*sth*/
} else {
boxTime = 2.0f;
}
}
if(boxTime > 0) {
GUI.Box(Rect(50,50,50,50,"not enough score"))
}
}
I hope than it will help you.