[英]error CS0111: Type 'Program' already defines a member called 'Main with the same parameter types c#
[英]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.