I followed the Video and after he added Invoke to delay the reloading mechanic I repeated the code he did and then it didn’t work anymore. If the Rocket hits an object which would make it reload it doesn’t work anymore. What in my code breaks the Reloading mechanic? I also got an Error Message in Unity after implementing Invoke: Assets\Scripts\CollisionHandler.cs(35,10): warning CS8321: The local function ‘Reloadlevel’ is declared but never used
Video showing what doesn’t work anymore
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("This thing is friendly");
break;
case "Finish":
LoadNextLevel();
break;
case "Fuel":
Debug.Log("You picked up some fuel");
break;
default:
Debug.Log("You blew up");
Invoke("Reloadlevel", 1f);
Debug.Log("Test");
break;
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
void Reloadlevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
}
}