- Home /
Toggle Menu just works one way
I have this code for toggling my optionsmenu but it only works when hiding the menu. In // I had another way that didn't work either so I went for the if else statements but that gave me the same result. I would rather have "optionsMenu.SetActive(!optionsMenu.activeSelf);" work, but I'll take any solution at this point. Sorry if it's a dumb question I've just started coding in C#
void Update() {
if (Input.GetKeyDown(KeyCode.Escape)) {
if (optionsMenu.activeInHierarchy == false) {
optionsMenu.SetActive(true);
}
else {
optionsMenu.SetActive(false);
}
//optionsMenu.SetActive(!optionsMenu.activeSelf);
}
}
Answer by andzq · Apr 20, 2021 at 11:40 PM
dumb question maybe. but this script does not by chance reside on the same gameobject you are setting active/false? because as a result of being set to inactive, the update method would no longer be called and "optionsMenu.SetActive(true)" will never be executed.
Answer by Norfinity · Apr 21, 2021 at 07:13 AM
Hi, if you disable the GameObject on which the script was added, the Update() method will no longer be called
Your answer
Follow this Question
Related Questions
Set Bool in Inspector to true or False 2 Answers
physics.OverlapSphere colliders 1 Answer
Unity Multiple Toggle Buttons Reversing 2 Answers
Toggling through music 1 Answer
Is there a toggle for snap to grid? 10 Answers