[英]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.