在C#中调用未执行

问题描述

我正在学习如何统一制作游戏,并按照brackeys教程进行学习,但是我遇到了麻烦,我的调用未触发重新启动。请帮助

using UnityEngine;
using  UnityEngine.SceneManagement;
public class Gamemanager : MonoBehaviour
{
bool gameHasEnded = false;
public float restartDelay = 1f;

public void EndGame()
{
    if (gameHasEnded == false)
    {
        gameHasEnded = true;
        Debug.Log("GAME OVER");
        Invoke("Restart()",restartDelay);
    }


void Restart()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}}
}`

解决方法

您以错误的方式调用Invoke方法。您只应提供方法的名称。

Invoke("Restart",restartDelay);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...