- Home /
Main Menu Buttons SetAtive(true) not working
I have made a Main Menu Scene where at Start Buttons and Text are invisible. After a short time these activated and that works fine when I start game. However, when my game finished and I go back to Main Menu these Buttons and Texts remain invisible. My Main Menu Script is as under:-
I need help in this regards as I am Beginner in Coding
Can you post full script and editor screenshots showing what exactly you are doing?
I just want to set visibility of buttons after 1 second on $$anonymous$$ain $$anonymous$$enu and it works perfect when I start game but when game finished and I go to $$anonymous$$ain $$anonymous$$enu by pressing Game Over $$anonymous$$enu; buttons of $$anonymous$$ain menu does not activate.
The script showed above is a part that used for this purpose.
Answer by akillingbeck · Sep 04, 2017 at 12:53 PM
Use unity functions OnEnable, OnDisable
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnEnable.html
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDisable.html
OnEnable gets called when the script becomes enabled (gameobject gets turned back on) OnDisable gets called when the script becomes disabled(gameobject gets turned off)
How can I implement OnEnable and OnDisable to make object visible/invisible? I will be thankful if you can guide me for this Function.
1) Remove Start and Awake functions 2) Add these functions:
private void OnEnable()
{
StartCoroutine(Frame(0.5f,true));
}
private void OnDisable()
{
StartCoroutine(Frame(0.0f,false));
}
public IEnumerator Frame(float waitFor,bool setActive)
{
yield return new WaitForSeconds(waitFor);
t2.SetActive(setActive);
yield return new WaitForSeconds(waitFor);
t1.SetActive(setActive);
yield return new WaitForSeconds(waitFor);
frame.SetActive(setActive);
b1.SetActive(setActive);
b2.SetActive(setActive);
b3.SetActive(setActive);
b4.SetActive(setActive);
}
Your answer

Follow this Question
Related Questions
how do you make a 3d person or object? 2 Answers
SQLite in Unity 4.x? 0 Answers
how to open probuilder basic 1 Answer
How do i make my player jump from an angle? (Wallrun Jump) 1 Answer
How to make atmospheric dust particles? 4 Answers