I’m trying to get a single UI button to, when pressed the first time, switch a bool from false to true, then the second time switch from true to false, and to be completely honest, i have no idea why it isn’t working. Here’s the code I’ve got so far:
void Start () {
chooseConsole = chooseConsole.GetComponent<Button> ();
testConsole = testConsole.GetComponent<Button> ();
testConsole.gameObject.SetActive(false);
chooseConsole.onClick.AddListener(() => { PopDown(); });
}
// Update is called once per frame
void Update () {
if (!Popdown) {
testConsole.gameObject.SetActive (false);
} else {
testConsole.gameObject.SetActive (true);
}
}
public void PopDown() {
if (!Popdown) {
Popdown = true;
} else {
Popdown = false;
}
}