- Home /
Don't understand how to create a bool for my code.
I'm trying to create a bool function that allows me to press a button called "Use" then once I pressed it I press another button called "Remove" which hides the panel the Use button was clicked on. I anyone could help me out and show me what to type, Id really appreciate it.
{ private int counter = 0;
public bool Return;
public GameObject[] Use;
public GameObject[] Panels;
public void Add()
{
Panels[counter--].SetActive(true);
}
public void Remove()
{
Panels[counter++].SetActive(false);
if (Return == true)
{
Use[counter++].SetActive(false);
}
}
}
Answer by ashkanaral · Feb 23, 2020 at 11:14 PM
Try this.
private int counter = 0;
public bool Return;
public GameObject[] Use;
public GameObject[] Panels;
bool isOn = true;
public void Add()
{
if(isOn == true) {
Panels[counter++].SetActive(true);
isOn = false;
}
}
public void Remove()
{
if(isOn == false){
Panels[counter--].SetActive(true);
isOn = true;
}
}
}
Answer by krubio000000 · Feb 23, 2020 at 11:39 PM
The remove button removes a panel after the use button is clicked for that panel to be removed
@ashkanaral I tried this, unfortunately, this didn't do anything to allow me to select the panel I want to remove and allow me to remove it. The sentence above explains what I meant a little better.
Before edited the bool isOn = true; before it was false.
Your answer
Follow this Question
Related Questions
Unity UI Button Switch Bool? 2 Answers
Enable/Disable JS Script Problem (AR) using CS 1 Answer
show "labelnew" after clicking a button and hide "labelold" 1 Answer
Hide GUI Text when button is pressed 1 Answer
A Button, A Boolean and 2 Textures. 2 Answers