Reputation: 3
So I have this weird issue where I am trying to call a method in Invoke
but it does not work for some reason IDK what am I doing wrong
public void EndGame ()
{
if (GameHasEnded == false)
{
GameHasEnded = true;
UnityEngine.Debug.Log("Game Over");
Invoke("Restart",2f);
}
void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Whenever I run this script I get a message
Trying to Invoke method:
GameManager.Restar
t Couldn't be called"
Upvotes: 0
Views: 447
Reputation: 90679
Why is your method nested inside the EndGame
method?
It should rather be
public void EndGame ()
{
if (!GameHasEnded)
{
GameHasEnded = true;
UnityEngine.Debug.Log("Game Over");
Invoke(nameof(Restart), 2f);
}
}
private void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
Upvotes: 4