繁体   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?

从 1 个脚本中得到 2 个错误,不知道发生了什么。 如果有人可以提供帮助,那就太好了。 错误在标题中,另一个是相同的,除了“开始”而不是“更新”

谢谢阅读

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);
    }
}

使用override运算符应该可以消除编译器错误,但我不是 Unity 开发人员,所以我不确定 Unity 是否会以正确的方式处理您的 class。 以下是您的操作方法:

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

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

我还找到了这篇文章,它将Start声明为IEnumerator而不是void ,因此也可以修复它。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM