My OnClick() won't trigger

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TitleScene : MonoBehaviour
{
    public string startLevel;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Level_Controller : MonoBehaviour
{

    private static int _nextLevelIndex = 2;
    private Enemy[] _enemies;


    
    private void OnEnable()
    {
        _enemies = FindObjectsOfType<Enemy>();
        

    }

    void Update()
    {
        Scene currentScene = SceneManager.GetActiveScene();
        string sceneName = currentScene.name;

        foreach(Enemy enemy in _enemies)
        {
            if (sceneName == "Level_2")
            {
                SceneManager.LoadScene("Level_3");

            }
            else if (enemy != null)
            return;
        }
        

        Debug.Log("You killed all enemies");

        
        _nextLevelIndex++;
        string nextLevelName = "Level" + "_" + _nextLevelIndex;
        SceneManager.LoadScene(nextLevelName);
    }
}

    public void NewGame()
    {
        Application.LoadLevel("Level_2");
    }

}

So, This is all the code I’m using to switch in between levels. For some reason, after being clicked, the button won’t switch to level 2. Level 1 is the title screen.

What I want to do is once the button is clicked, It will automatically move to level 2 and start there. Once it starts, it will check if all enemies are down, once they are, A new level is loaded and rinse and repeat. Since there are no enemies in level 1, or the title screen, I tried to load level 2 with an OnClick component inside the button component. Once it is clicked, it would load level 2. But the OnClick never seems to trigger no matter how many times its pressed. it doesn’t seem to respond to clicking at all.


I don’t think you got any problem in your script, so I guess you may not build the scene.
Click File > Build Settings
Pull both of your scene into the window.