I can’t get this to work on one of my scenes, it’s supposed to act as a main menu to be able to start the actual game. I have never managed to get the SceneManager.LoadScene function to work, but in this case it seems to not even work to click on the actual button. It’s just the default Unity UI button with nothing changed except the text and the fact that I have added the script above (and I am of course referencing to the button in the inspector)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MenuController : MonoBehaviour
{
public Button StartButton;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
StartButton.onClick.AddListener(StartGame);
}
void StartGame()
{
Debug.Log("Working?");
SceneManager.LoadScene(1);
}
}
I tried adding the onClick method to the button in Unity itself first but that didn’t work either, so that’s why I tried writing the script too. As I said, using “onClick” on button works perfectly fine in my other scene… I am clueless.