Hey,VS told me "ReloadLevel"is declared but never used. Bur I did use it in the Invoke.
and in the unity :Trying to Invoke method: CollisionScript.ReloadLevel couldn’t be called.
I really dont know where is the problem. Can anybody save me?
here is the code:
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionScript : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
switch(other.gameObject.tag)
{
case "Start":
Debug.Log("start");
break;
case "Finish":
LoadNext();
break;
case "Fuel":
Debug.Log("Fuel");
break;
default:
Boom();
break;
}
void ReloadLevel()
{
int Level = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(Level);
}
void Boom()
{
GetComponent<Mover>().enabled = false;
Invoke(methodName: "ReloadLevel", time: 0.5f);
}
void LoadNext()
{
int Level = SceneManager.GetActiveScene().buildIndex;
int NextLevel = Level + 1;
if(NextLevel>SceneManager.sceneCountInBuildSettings)
{
NextLevel = 0;
}
SceneManager.LoadScene(NextLevel);
}
}
}