- Home /
Problem with Main Menu
Hi, have this main menu system that I'm working on and every time I switch to another panel like Settings or Achievements the Event System does come with it, making my controller no work on that menu.
[Header("Event System")]
public EventSystem ES;
private GameObject Selection;
private NextScene nextScene;
[Space]
[Header("Canvases")]
public GameObject G_MainMenu;
public GameObject G_Settings;
public GameObject G_Achievements;
void Start()
{
Selection = ES.firstSelectedGameObject;
}
private void Update()
{
if (ES.currentSelectedGameObject != Selection)
{
if (ES.currentSelectedGameObject == null)
{
ES.SetSelectedGameObject(Selection);
}
else
{
Selection = ES.currentSelectedGameObject;
}
}
}
public void StartGame()
{
nextScene.ToNextScene();
}
public void MainMenu()
{
G_MainMenu.SetActive(true);
G_Settings.SetActive(false);
G_Achievements.SetActive(false);
ES.SetSelectedGameObject(Selection);
}
public void Settings()
{
G_MainMenu.SetActive(false);
G_Settings.SetActive(true);
G_Achievements.SetActive(false);
ES.SetSelectedGameObject(Selection);
if (Input.GetKeyDown(KeyCode.Joystick1Button1))
{
MainMenu();
}
}
public void Achievements()
{
G_MainMenu.SetActive(false);
G_Settings.SetActive(false);
G_Achievements.SetActive(true);
ES.SetSelectedGameObject(Selection);
if (Input.GetKeyDown(KeyCode.Joystick1Button1))
{
MainMenu();
}
}
public void QuitGame()
{
Application.Quit();
Debug.Log("Game is now Quitting....");
}
Answer by Bunny83 · Nov 27, 2019 at 12:26 AM
Why do you manually serialize a reference to an EventSystem when the EventSystem is actually a singleton and has a current property. Storing references to singletons is generally a bad idea.
Your answer
Follow this Question
Related Questions
Gunfire Sound Gets Cut Off When I Release the Aim Button. Help? 2 Answers
Check if mouse is over UI 4 Answers
Can I Simulate the "Submit" Event with Gamepad Buttons? 0 Answers
Best way to move a player (touch based) using the event system in Unity 5? 0 Answers
UI - Assigning Event Callbacks Via Script Fails on GameObjects Instantied Via Script 0 Answers