[英]Cannot write my code right, because of an error CS0111
I'm a beginner in programming, So i don't know how to fix this error.我是编程初学者,所以我不知道如何解决这个错误。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZombieScript : MonoBehaviour
{
public Transform player;
public Transform zombie;
public GameObject zombieScript;
bool canActive = false;
void Start()
{
if (canActive == false) { zombieScript.SetActive(true); }
}
void Update()
{
UnityEngine.Debug.Log(Mathf.Abs(Vector2.Distance(player.transform.position, zombieScript.transform.position)));
if (Mathf.Abs(Vector2.Distance(player.transform.position, zombieScript.transform.position)) <= 10.00000 && canActive == false)
{
zombieScript.SetActive(true);
canActive = true;
}
}
}
Unity writes:统一写道:
Assets\ZombieScript.cs(5,14): error CS0101: The namespace '' already contains a definition for 'ZombieScript'
Assets\ZombieScript.cs(5,14): 错误 CS0101: 命名空间 '' 已经包含 'ZombieScript' 的定义
Assets\ZombieScript.cs(12,10): error CS0111: Type 'ZombieScript' already defines a member called 'Start' with the same parameter types
Assets\ZombieScript.cs(12,10): error CS0111: Type 'ZombieScript' 已经定义了一个名为 'Start' 的成员具有相同的参数类型
Assets\ZombieScript.cs(17,10): error CS0111: Type 'ZombieScript' already defines a member called 'Update' with the same parameter types
Assets\ZombieScript.cs(17,10): error CS0111: Type 'ZombieScript' 已经定义了一个名为 'Update' 且参数类型相同的成员
in advance, thank u <3提前,谢谢你<3
A basic structure of a C# class looks like this: C# class 的基本结构如下所示:
using ...
namespace CompanyXYZ.ProductABC
{
public class Entity
{
// Constructors, properties, methods & etc.
...
}
}
CS1011 compiler error will be thrown whenever it found more than one definition within the same namespace.只要在同一命名空间中发现多个定义,就会引发CS1011编译器错误。
Namespace allows us to avoid conflict of classes with the same name by grouping them in different namespaces. 命名空间允许我们通过将具有相同名称的类分组到不同的命名空间中来避免它们的冲突。
In this case, you probably have more than one ZombieScript
defined under the same namespace which is not shown in your code.在这种情况下,您可能在同一个名称空间下定义了多个
ZombieScript
,而这些名称空间并未显示在您的代码中。 Therefore, kindly check if you have it defined somewhere else (within the same namespace) and if found it you're good to go!因此,请检查您是否在其他地方(在同一名称空间内)定义了它,如果找到它,您就可以开始了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.