简体   繁体   English

如何修复 Unity/Vscode 中的错误 CS0111?

[英]How do I fix error CS0111 in Unity/Vscode?

I'm just starting to learn to develop games in Unity with Vscode, so I found a Brackeys tutorial on it.我刚开始学习用 Vscode 在 Unity 中开发游戏,所以我找到了一个 Brackeys 教程。 I've been watching the series for a while, until I came across an issue;我一直在看这个系列,直到遇到一个问题; I got an error while following along with the 9th episode that says: Assets\Scripts\GameManager.cs(20,6): error CS0111: Type 'GameManager' already defines a member called 'Restart' with the same parameter types跟随第 9 集时出现错误:Assets\Scripts\GameManager.cs(20,6): error CS0111: Type 'GameManager' already defined a member called 'Restart' with the same parameter types

I have tried to figure out the issue based on what the error says, but I couldn't get it to work.我试图根据错误的内容找出问题,但我无法让它工作。 I was hoping someone could help.我希望有人能帮忙。

Here is my code:这是我的代码:

using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
   
bool gameHasEnded = false;
public float restartDelay = 1f;
public void CompleteLevel ()
{Debug.Log ("You did it!");
}
public void EndGame ()
{
    if (gameHasEnded == false)
   { 
       gameHasEnded = true;
    Debug.Log ("Game Over");
   Invoke("Restart", restartDelay);
    }
}
 

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


}

It says that your "Restart'" method has been redefined.它说您的“重新启动”方法已被重新定义。 Try changing the "Restart" method to the "Restarts" method.尝试将“重新启动”方法更改为“重新启动”方法。

 void Restarts ()
{
  SceneManager.LoadScene(SceneManager.GetActiveScene().name);    
}

thank you hope it helps谢谢希望对你有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unity 中的错误 CS0111:已定义 Update() - error CS0111 in Unity: Update() is already defined 有 2 个错误,“开始”和“更新”错误 CS0111:类型“敌人”已经定义了一个名为“开始”的成员,具有相同的参数类型我该如何解决? - Got 2 errors with 'start' and 'update' error CS0111: Type 'Enemy' already defines a member called 'Start' with the same parameter types how can i fix? 由于错误 CS0111,无法正确编写我的代码 - Cannot write my code right, because of an error CS0111 错误 CS0111:“程序”类型已经定义了一个名为“Main”的成员,具有相同的参数类型 c# - error CS0111: Type 'Program' already defines a member called 'Main with the same parameter types c# 我怎么能在统一中修复错误(cs0120)? - How could i fix an error (cs0120) in unity? 加载统一 C# 脚本时,如何修复 VSCode 中的 IntelliSense 不起作用和 OmniSharp 错误消息? - How do I to fix IntelliSense in VSCode not working and OmniSharp error messages when loading unity C# scripts? 如何防止出现 CS0161 错误? - 团结 - How do i prevent the CS0161 error? - unity 如何修复此参考错误? 统一 C# - CS0176 - How do I Fix This Reference Bug? Unity C# - CS0176 如何在 Unity 2d 中修复此错误 (CS0102) - How can I fix this error (CS0102) in Unity 2d 如何在Unity C#脚本中解决错误“ CS0029”? - How can I fix the error “CS0029” in my Unity C# script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM