I’m getting an error Trying to Invoke method: CollisionHandler.ReloadLevel couldn’t be called.
I know I should paste the code in a code block but wanted to show the problems shown in the tab about ReloadLevel being declared but never used
Here is my code block
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("You've hit a friendly object!");
break;
case "Finish":
LoadNextLevel();
Debug.Log("You've finished the level!");
break;
case "Fuel":
Debug.Log("That's fuel. You need that");
break;
default:
Invoke("ReloadLevel" , 1f);
break;
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}
}