im making a pause menu and i want to have each option labeled with the designated button next to it, but im not sure the script i could use to “click” an on screen button.
i’ve already tried just labeling the buttons and having the corresponding button do what i want it to but that just makes my pause menu close immediately.
~C#~
void Update() {
if (Input.GetButtonUp("A"))
Time.timeScale = 1.0f;
((Behaviour)player.GetComponent("MouseLook")).enabled = true;
((Behaviour)cam.GetComponent("MouseLook")).enabled = true;
((Behaviour)cam.GetComponent("ShowSkin")).enabled = false;
}
ShowSkin is the name of my script with the GUI… but if i add this, as soon as i open my pause menu it closes instantly.
2 ways to answer this question.
- tell a way to “click” a button with script
- help me fix my script here so it doesn’t close immediately.
please help
Unrelated tip: use the generic GetComponent: // C# player.GetComponent<MouseLook>().enabled = true; // JS player.GetComponent.<MouseLook>().enabled = true; It's more efficient and more readable since no need to cast.
– WazPlease go back and show us when you tried to do it in your OnGUI, because that was the correct approach, whereas what you have now looks like you are heading off in the wrong direction. Having a button shortcut a GUI button is pretty straightforward, so you must have made a small mistake back then (eg. put the GUI.Button after the Input.GetButtonUp in the
– Wazifpredicate).As you are not the first one to add modding to your game there are others who have already done this for you. Just check how others do this. Do not try to unnecessarily reinvent the wheel unless it is for educational purposes because you yourself want to learn how to do it and enjoy the process of searching for a solution.
– Captain_Pineapple