Unity3d 声明了本地函数“RestartGame”,但从未使用过程序集CSharp
我真的需要帮助,当我把Invoke放在C中时,我有一个错误: 声明了本地函数“RestartGame”,但从未使用过程序集CSharp 我真的不知道为什么会这样,但下面是代码: 使用UnityEngine; 使用UnityEngine.SceneManagement 公共类GameManager:MonoBehavior { bool gamehasend=falseUnity3d 声明了本地函数“RestartGame”,但从未使用过程序集CSharp,unity3d,delay,invoke,Unity3d,Delay,Invoke,我真的需要帮助,当我把Invoke放在C中时,我有一个错误: 声明了本地函数“RestartGame”,但从未使用过程序集CSharp 我真的不知道为什么会这样,但下面是代码: 使用UnityEngine; 使用UnityEngine.SceneManagement 公共类GameManager:MonoBehavior { bool gamehasend=false public float restartDelay = 2f; public void EndGame() { if (
public float restartDelay = 2f;
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("RestartGame", restartDelay);
}
void RestartGame ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}unity手册:为了获得更好的性能和可维护性,请改用协同程序。 试着这样做:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
bool gameHasEnded = false;
public float restartDelay = 2f;
private IEnumerator coroutine;
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
coroutine = RestartDelayed(restartDelay);
StartCoroutine(coroutine);
}
void RestartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
IEnumerator RestartDelayed(float delay)
{
yield return new WaitForSeconds(delay);
RestartGame();
}
}
}
我对flyingchris的答案投了赞成票,但为了解释您的错误消息,我假设它是一条黄色警告消息,即您从未在代码中的任何地方直接调用RestartGame方法,但是您正在调用它。调用通常用于UnityEvents,协程通常用于延迟方法。您好,我尝试了代码,但由于某些原因它会弄乱一切,请帮助弄乱一切意味着什么?是否有错误消息?如果是的话,你能告诉我们出现了哪些错误吗?发布你到目前为止得到的信息如果你使用的flyingchris代码有语法错误,应该是StartRoutineCorroutine;重新启动延迟代替StartRoutinerEstartDelay;隐马尔可夫模型。。。你是对的。我正在更改脚本。很抱歉我没有收到任何错误消息