So, I recently started a platformer project, and just today discovered you guys were adding this new 2D platformer section to the course!
My issue is, im trying to use the LevelManager from previous sections in this game, my menu is working just fine, but when I try to load the lose screen with a lose collider, by making the player touch the collider, unity gives me this error: NullReferenceException: Object reference not set to an instance of an object LoseCollider.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts/LoseCollider.cs:14)
Game Scene:
LevelManager script:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {
public void LoadLevel(string name) {
Debug.Log("Level load requested for: " + name);
Application.LoadLevel(name);
}
public void QuitRequest() {
Debug.Log("Quit Requested");
}
public void LoadNextLevel() {
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
Loose Collider script:
using System.Collections.Generic;
using UnityEngine;
public class LoseCollider : MonoBehaviour {
private LevelManager levelManager;
void Start() {
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
void OnCollisionEnter2D(Collision2D collision) {
levelManager.LoadLevel("Loose Screen");
}
void OnTriggerEnter2D(Collider2D trigger) {
print ("trigger");
}
}
I dont know what is wrong, thanks in advance