Hey, I want the game to restart after 2 seconds but it tells me
“Trying to Invoke method: GameManager.Restart couldn’t be called.”
This is my script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public float Delay_victory = 2f;
bool Endgame = false;
public void GameOver(){
if (Endgame == false){
Endgame = true;
Debug.Log("Game over");
Invoke ("Restart", Delay_victory);
//restart game
}
void Restart () {
// you can use VVVV OR SceneManager.LoadScene("Level 1");
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
You appear to have put the definition of Restart() inside of the GameOver() function.
2 Likes
I’ve fixed the issue that you told but still having problem.
How to resolve?
Nobody knows what problem you fixed or what problem you are now having. Try starting your own thread and describe your problem.
2 Likes
For those getting: “Trying to Invoke method: GameManager.Restart couldn’t be called.” Make sure the format is like this:
public void EndGame(){
}
void Restart(){
}
Notice the functions are outside of each other and not like this:
public void Endagme(){
void Restart(){
}
}
i commited the same mistake, this is a coment from the brackeys video.
1 Like
@aparica0 Thanks so much for explaining the fix, I need to pay more attention to the curly brackets.
it doesn’t restart after 2 seconds right, in my case doesn’t, if it is in your case, kindly let me know!
Thanks man! Ive been looking for the problem for a few hours and this saved me! Thank you so much man, couldn’t have appreciated something more!