I have a button (in UI), that I want to hide sometimes (but show again later), which means that it shouldn't show anymore and I shouldn't be able to click it. The only solution I found (that has actually managed to hide the button), is SetActive()
.
But in Update()
, when I do SetActive(false)
(the true/false is controlled with the variable wave_happening
in my script), Update()
doesn't run anymore, so I can't set it to true again.
When I do GameObject.Find("Start Button").SetActive(true)
in another script, it just gives me a NullReferenceException (Object reference not set to an instance of an object).
This is my Update()
function:
void Update() {
wave_happening = enemy_spawner_script.wave_happening;
Debug.Log(wave_happening);
transform.gameObject.SetActive(wave_happening);
}
Is there a solution to stop this problem, or another way to hide a button?
I'm fairly new to Unity and C#, so I don't know very much.
question from:
https://stackoverflow.com/questions/65601202/hide-and-show-a-button-in-unity-c 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…