After setting up Invoke in section 49 in Udemy. Invoke could not call the on the method because it was in the wrong class. Rick added a bracket and used a shortcut. I tried the same but it didnt work. No matter how I try to restructure my classes they always lead to errors. Here is what my code looks like.
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
private void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log ("this is friendly");
break;
case "Finish":
Debug.Log("This is the goal");
LoadNextLevel();
break;
default:
Invoke ("ReloadLevel", 2f);
break;
}
}
private static void ReloadLevel()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentScene);
}
private static void LoadNextLevel()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
int nextScene = currentScene + 1;
if (nextScene == SceneManager.sceneCountInBuildSettings)
{
nextScene = 0;
}
SceneManager.LoadScene(nextScene);
}
}