简体   繁体   English

由于错误 CS0111,无法正确编写我的代码

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

相关问题 如何修复 Unity/Vscode 中的错误 CS0111? - How do I fix error CS0111 in Unity/Vscode? Unity 中的错误 CS0111:已定义 Update() - error CS0111 in Unity: Update() is already defined 错误 CS0111:“程序”类型已经定义了一个名为“Main”的成员,具有相同的参数类型 c# - error CS0111: Type 'Program' already defines a member called 'Main with the same parameter types c# 有 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? 由于此错误,我的代码行无法工作? - My code line cannot work because of this error? 找不到我的代码有任何问题,但是我有八条错误消息。 四个 CS1519、两个 CS1001、CS1022 和 CS8124 - Cannot find any issues with my code but, I have a eight error messages. Four CS1519, two CS1001, CS1022 and CS8124 无法获取用户输入以在 C# 中写入我的文本文件(错误表示无法访问路径,因为它已在使用中) - Cannot get user input to write to my text file in C# (error says path cannot be accessed because it is already in use) 该进程无法访问该文件,因为尝试写入文件时出错 - The process cannot access the file because error while trying to write to a file 为什么我的代码中出现 CS1001 错误? - Why am I getting a CS1001 error in my code? 无法修改控件集合,因为控件包含代码块错误 - The Controls collection cannot be modified because the control contains code blocks Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM