简体   繁体   English

有 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?

Got 2 errors from 1 script and dont know whats happening.从 1 个脚本中得到 2 个错误,不知道发生了什么。 If anyone can help that would be great.如果有人可以提供帮助,那就太好了。 Error is in the title and the other one is the same except instead of 'Start' its 'Update'错误在标题中,另一个是相同的,除了“开始”而不是“更新”

Thanks for reading谢谢阅读

using UnityEngine;

public class Enemy : MonoBehaviour
{
    public float health = 50f;
    private Rigidbody rb;
    
    // Start is called before the first frame update
    void Start()
    {
        rb = this.GetComponent<Rigidbody>();
    }
    
    // Update is called once per frame
    void Update()
    {
        Vector3 direction = player.position - transform.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        float y = Quaternion.identity.eulerAngles.y;
        float z = Quaternion.identity.eulerAngles.z;
        rb.rotation = Quaternion.Euler(angle, y, z);
    }
}

Using the override operator should get rid of the compiler errors, but I'm not a Unity dev so I'm not sure if Unity will treat your class in the correct way.使用override运算符应该可以消除编译器错误,但我不是 Unity 开发人员,所以我不确定 Unity 是否会以正确的方式处理您的 class。 Here's how you would do it:以下是您的操作方法:

    override void Start()
    {
    ...
    }
    
    // Update is called once per frame
    override void Update()
    {
    ...
    }

You can read more about the override operator here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/override您可以在此处阅读有关覆盖运算符的更多信息: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/override

I also found this article and it declares Start as an IEnumerator rather than a void so that may fix it too.我还找到了这篇文章,它将Start声明为IEnumerator而不是void ,因此也可以修复它。

暂无
暂无

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

相关问题 错误 CS0111:“程序”类型已经定义了一个名为“Main”的成员,具有相同的参数类型 c# - error CS0111: Type 'Program' already defines a member called 'Main with the same parameter types c# 我该如何修复错误:Type Form1&#39;已经定义了一个名为&#39;Dispose&#39;的成员,它具有相同的参数类型? - How can i fix the error: Type Form1' already defines a member called 'Dispose' with the same parameter types? 如何修复 Unity/Vscode 中的错误 CS0111? - How do I fix error CS0111 in Unity/Vscode? Unity 中的错误 CS0111:已定义 Update() - error CS0111 in Unity: Update() is already defined 类型&#39;Startup&#39;已经定义了一个名为&#39;Configuration&#39;的成员,它具有相同的参数类型 - Type 'Startup' already defines a member called 'Configuration' with the same parameter types 错误已使用相同的参数类型定义了一个名为“索引”的成员 - Error already defines a member called 'Index' with the same parameter types 错误 - 已经使用相同的参数类型定义了一个名为“InitializeComponent”的成员 - Error - already defines a member called 'InitializeComponent' with the same parameter types C#错误:类型'x'已经定义了一个名为'y'的成员,它具有相同的参数类型 - C# error: Type 'x' already defines a member called 'y' with the same parameter types 错误1类型“ Pay”已经使用相同的参数类型定义了一个名为“ ComputePay”的成员 - Error 1 Type 'Pay' already defines a member called 'ComputePay' with the same parameter types C#:专用模板方法-错误:类型“…”已经定义了具有相同参数类型的成员“…” - C#: specialized template method - Error: Type '…' already defines a member called '…' with the same parameter types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM