Reputation: 11343
I have a Main Menu empty GameObject under it as child a Canvas and under the Canvas as children the buttons. The first button is Start New Game.
The Main Menu button text is set to New Game. A script name Main Menu is attached to the empty GameObject Main Menu.
When running the game and clicking on the button New Game it does nothing. And it's never getting to the method StartNewGame :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainMenu : MonoBehaviour
{
public Canvas mainMenuCanvas;
public PlayerController playerController;
public CamMouseLook camMouseLook;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void StartNewGame()
{
mainMenuCanvas.enabled = false;
playerController.enabled = true;
camMouseLook.enabled = true;
}
}
Upvotes: 0
Views: 125
Reputation:
You're missing the EventSystem
object in your hierarchy, which is responsible for handling interactions with the UI. You can import it by right-clicking on the hierarchy and Add... > EventSystem.
Upvotes: 3