I have researched the correct code and got most of it working, I can change Level from 1 to 2, but it will not allow me to change the level from Level_02 to Level_03 my Brick.cs code:
PS in my Build Settings it is all index correctly, from 0 to 5.
using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine; public class Brick : MonoBehaviour { public int maxHits; private int timesHit; private LevelManager levelManager; // Use this for initialization void Start () { timesHit = 0; levelManager = GameObject.FindObjectOfType<LevelManager> (); } // Update is called once per frame void Update () { } void OnCollisionEnter2D (Collision2D col) { timesHit++; SimulateWin (); } // TODO Remove this method once we can actually win! // Comes from LevelManager (LoadNextLevel Function) void SimulateWin(){ levelManager.LoadNextLevel (); } }
Here is my LevelManager.cs
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine.SceneManagement;
> using UnityEngine;
>
> public class LevelManager : MonoBehaviour {
>
> // Naming a Level
> public void LoadLevel(string name){
> //Debug.Log ("Level load requested for: " + name);
> SceneManager.LoadScene (name);
> }
>
> public void QuitRequest(string name){
> Debug.Log("I want to quit! " + name);
> Application.Quit ();
> }
> // Creates the next level
> public void LoadNextLevel(){
> SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
> }
>
> }
Some Reason Unity needed to fix itself. ![]()