I’m not getting any errors or Debug.Log messages in the console when Player makes contact with Level Exit, even though I put Debug.Log lines in both OnCollisionEnter2D() and LoadNextLevel(). Am I overlooking something?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelExit : MonoBehaviour {
[SerializeField] float LevelLoadDelay = 2f;
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("Collision detected");
StartCoroutine(LoadNextLevel());
}
IEnumerator LoadNextLevel()
{
yield return new WaitForSecondsRealtime(LevelLoadDelay);
Debug.Log("LoadNextScene() called");
var currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex + 1);
}
}