How to make buttons disappear and reappear in the background?
So I am new to programming and I have buttons that I want to appear when I click one button how would i do that like if i click an "about button" and then that disappears and arrows come up?
Answer by Dibbie · Jun 16, 2016 at 03:42 PM
Using the buttons enabled property is probably what you want.
On your buttons click event - however you are doing it (the most standard way is to make a public function and link that function to the buttons OnClick in the Inspector), then just hide the button. Even easier if you give your function 1 parameter being a string or a enum (not sure if a "button" parameter would work but you could try it) and run through a bunch of if-else statements to hide the correct button and such. Or just tie 2 functions to every button, that hides a specific button and shows a specific button.
You could also use a caller method which might be a bit more complicated, to essentially use one function in the most efficient way to enable/disable buttons.
Answer by Shippety · Jun 16, 2016 at 04:21 PM
One way to do that would be to deactivate the button that you want to disappear, using thisButton.SetActive (false);
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
And activate the other button and or info you want to appear at the same time. So basically you'd have all of the buttons or arrows or what have you, with some of them activated on start and some deactivated. Then you could make some active at some times, and deactivate others.
This is an example of how you could do this:
public GameObject button1;
public GameObject button2;
void Start ()
{
button1.SetActive (false);
button2.SetActive (true);
}
public void clickThisButton()
{
button1.SetActive (true);
button2.SetActive (false);
}
(Remember not to put anything activating or deactivating objects on one of the objects itself, perhaps put it on the canvas or an empty serving as a scene manager)
You'll need to select the clickThisButton() function on the button component for the right code to be executed on that button click.
but then how do i get the text to go and come back and also if i do the SetActive the button disappears and then i can't bring it back.
what I did was deactivate intractable but then then text is still there and what i do want is to deactivate the button using code but then clicking another button to bring it back after deactivating.
Your answer
Follow this Question
Related Questions
Disabling random GUI Button from array 0 Answers
Button mouseover only works when other canvas is active 0 Answers
Instantiated Buttons to have separate On-click functions 0 Answers
Unity - Button causes lag on a mobile device 2 Answers
How would I pull or push buttons (their position) if they're unactive, active? 0 Answers