- Home /
Question by
Christophfen · May 28, 2013 at 07:41 PM ·
boxdraw
Script only runs once?
I have a button that draws a gui box, and a button that shuts the box, however after I shut the box, I can no longer open it again from the open box button.
Any ideas?
using UnityEngine;
using System.Collections;
public class Gui : MonoBehaviour {
bool boxcheck1 = false;
bool boxcheck2 = false;
bool boxcheck3 = false;
bool boxcheck4 = false;
bool shutboxcheck1 = false;
//Campaign box
void OnGUI() {
if (GUI.Button(new Rect(250, 700, 90, 20), "Campaign")){
boxcheck1 = true;
}
if (boxcheck1 == true) {
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
GUI.Box(new Rect(10, 10, 1008, 680), "");
if (GUI.Button(new Rect(870, 650, 110, 20), "Close window")){
shutboxcheck1 = true;
}
if (shutboxcheck1 == true) {
boxcheck1 = false;
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
}
}
Comment
Best Answer
Answer by Coderdood · May 28, 2013 at 08:12 PM
The problem is that shutboxcheck1 will still be true when you click the campaign button - instantly closing the window again. Try this:
//Campaign box
void OnGUI()
{
if (GUI.Button(new Rect(250, 700, 90, 20), "Campaign"))
{
boxcheck1 = true;
}
if (boxcheck1 == true)
{
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
GUI.Box(new Rect(10, 10, 1008, 680), "");
if (GUI.Button(new Rect(870, 650, 110, 20), "Close window"))
{
shutboxcheck1 = true;
}
if (shutboxcheck1 == true)
{
boxcheck1 = false;
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
shutboxcheck1 = false; // NEW
}
}
}
Answer by ExpiredIndexCard · May 28, 2013 at 07:47 PM
There needs to be a way the booleans can be set to true is my guess. Try that
Your answer
Follow this Question
Related Questions
Script only runs once? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Simple Backpack "Pick up and drop" 1 Answer
how to detect if a non-moving object exist in a position? 1 Answer
Car steering control 1 Answer