- Home /
hide button
I want to do is when I click on one button that button will be hidden and another button will be shown in the same place.
bool toggle = false; bool toggle1 = false; void OnGUI(){
GUI.Box (new Rect (0, 0, 800, 80), "Furnitures");
if (GUI.Button (new Rect (20, 10, 100, 50), "Move")) {
toggle = !toggle;
}
if (toggle) {
if (GUI.Button (new Rect (20, 400, 50, 50), "Bed")){
toggle1 = !toggle1;
toggle = toggle;
}
if (toggle1) {
if (GUI.Button (new Rect (20, 400, 50, 50), "Bed")){
}
}
It is difficult to understand your code. Are you wanting to first click "$$anonymous$$ove" and then have one of two options displayed? You have "Bed" twice, is the reason I am asking.
The move button will never be removed as it is not in a conditional statement. So it will always show up even if the toggle value is changed
Answer by RudyTheDev · Mar 01, 2014 at 05:11 PM
Here is simple code for "when I click on one button that button will be hidden and another button will be shown in the same place". Not sure what your code example is doing though, as pointed above, it seems to be weirdly constructed (`toggle = toggle;`?).
public class Toggle : MonoBehaviour
{
private bool moveActive = false;
private void OnGUI()
{
if (!moveActive)
{
if (GUI.Button(new Rect(20, 10, 100, 50), "Move"))
{
moveActive = true; // activate moving
}
}
else
{
if (GUI.Button(new Rect(20, 10, 100, 50), "Bed"))
{
moveActive = false; // back
}
}
}
}