Unity ошибка cs0101

I am studying access modifiers and I came across the following error in my code. Can someone explain to me and help me solve it?
AssetsTestesScriptsmodificadoracesso.cs(40,7): error CS0101: The namespace ‘< global namespace >’ already contains a definition for ‘Felino’

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class modificadoracesso : MonoBehaviour
{

    Felino gatoFase1; // criar objeto
    Felino gatoFase2;
    Filha fi;

    // Start is called before the first frame update
    void Start()
    {
        gatoFase1 = new Felino (); //objeto
        gatoFase2 = new Felino ();
        fi = new Filha();

        //gatoFase1.nome = "mark";
        gatoFase1.ataque();
        gatoFase1.corPelo = "Preto";
        gatoFase1.forca = 100;

        //gatoFase2.nome = "Zuck";
        gatoFase2.corPelo = "Marrom";
        gatoFase2.ataque();

        fi.acessa();

    }

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

class Felino : MonoBehaviour
{

    //Características = atributos
    //protected trabalha dentro a classe ou dentro de uma classe filha
    protected string nome;
    public string corPelo;
    public int forca;

    //Ações = métodos
    public void ataque()
    {
        print("Ataquei");
    }

}

class Filha : Felino
{
    public void acessa()
    {
        nome = "Gato";
    }
}

I’ve looked for some answers but so far nothing works

asked Aug 19, 2020 at 17:57

ToDyToScAnO's user avatar

3

Unless a class is in a namespace, the class it in the ‘global namespace’. Add a namespace around your classes. I’m not saying this is the complete answer, but not using namespaces is a bad idea. Namespaces usually start with the name of your solution and will be placed there automatically when you create a new class.

Try this:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ToDyToScAnO // <-- This is a namespace
{
  public class modificadoracesso : MonoBehaviour
  {

    Felino gatoFase1; // criar objeto
    Felino gatoFase2;
    Filha fi;

    // Start is called before the first frame update
    void Start()
    {
        gatoFase1 = new Felino (); //objeto
        gatoFase2 = new Felino ();
        fi = new Filha();

        //gatoFase1.nome = "mark";
        gatoFase1.ataque();
        gatoFase1.corPelo = "Preto";
        gatoFase1.forca = 100;

        //gatoFase2.nome = "Zuck";
        gatoFase2.corPelo = "Marrom";
        gatoFase2.ataque();

        fi.acessa();

    }

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

class Felino : MonoBehaviour
{

    //Características = atributos
    //protected trabalha dentro a classe ou dentro de uma classe filha
    protected string nome;
    public string corPelo;
    public int forca;

    //Ações = métodos
    public void ataque()
    {
        print("Ataquei");
    }

}

 class Filha : Felino
 {
    public void acessa()
    {
        nome = "Gato";
    }
 }
}

answered Aug 19, 2020 at 18:48

Neil's user avatar

NeilNeil

10.8k2 gold badges30 silver badges56 bronze badges

0

This usually occurs when you drag and drop a script to another folder, while your text editor still has the script open. When you save the file in text editor, the file is re-created in old location, so you have a duplicate script for the moved script.

answered Jul 10, 2022 at 19:44

Emmanuel Mukombero's user avatar

It’s only because you have another script in your project with this name!
Maybe you accidentally duplicate it or something.

answered Oct 16, 2021 at 10:58

azin's user avatar

azinazin

113 bronze badges

Ребят, помогите пожалуйста. У меня казалось бы всего лишь 27 строчек кода, но откуда в 3 ошибки, не понятно… Вроде всё правильно на писал.
1 Ошибка CS0101: The namespace » already contains a definition for ‘Destroyable’
2 Ошибка CS0111: Type ‘Destroyable’ already defines a member called ‘Start’ with the same parameter types
3 Ошибка CS0111: Type ‘Destroyable’ already defines a member called ‘Update’ with the same parameter types

Мой код

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Destroyable : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            collision.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * 8f, ForceMode2D.Impulse);
            gameObject.GetComponentInParent<Enemy>().startDeath();
        }
    }
}

«error CS0101: The namespace `global::’ already contains a definition for»

Hi, I’m creating a 3d rpg and I have an object called «NPC» and a script called «NPC» and believe this is what is creating the error «error CS0101: The namespace `global::’ already contains a definition for NPC» but I don’t know how I can fix it.

Here is my script called «NPC»(by the way I am using it on the «NPC» Game Object) : using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;

public class NPC : Interactable { public override void Interact() { Debug.Log(«Interacting with NPC»); } }

Any help is greatly appreciated, thanks.

C# Compiler Error

CS0101 – The namespace ‘namespace’ already contains a definition for ‘type’

Reason for the Error

You will receive this error when your namespace has duplicate identifiers that is declared.

For example, the below code snippet contains the namespace DeveloperPublish but contains two classes with the same name “Class1”.

namespace DeveloperPublish
{
    class Class1
    {

    }

    class Class1
    {

    }
    public class Program
    {
        public static void Main()
        {

        }
    }
}

This will result with the error.

Error CS0101 The namespace ‘DeveloperPublish’ already contains a definition for ‘Class1’ ConsoleApp2 C:UsersadminsourcereposConsoleApp2ConsoleApp2Program.cs 8 Active

C# Error CS0101 – The namespace 'namespace' already contains a definition for 'type'

Solution

To fix the error, rename or delete one of the duplicate identifiers. If it is a class, try moving it to a different namespace.

I am studying access modifiers and I came across the following error in my code. Can someone explain to me and help me solve it?
AssetsTestesScriptsmodificadoracesso.cs(40,7): error CS0101: The namespace ‘< global namespace >’ already contains a definition for ‘Felino’

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class modificadoracesso : MonoBehaviour
{

    Felino gatoFase1; // criar objeto
    Felino gatoFase2;
    Filha fi;

    // Start is called before the first frame update
    void Start()
    {
        gatoFase1 = new Felino (); //objeto
        gatoFase2 = new Felino ();
        fi = new Filha();

        //gatoFase1.nome = "mark";
        gatoFase1.ataque();
        gatoFase1.corPelo = "Preto";
        gatoFase1.forca = 100;

        //gatoFase2.nome = "Zuck";
        gatoFase2.corPelo = "Marrom";
        gatoFase2.ataque();

        fi.acessa();

    }

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

class Felino : MonoBehaviour
{

    //Características = atributos
    //protected trabalha dentro a classe ou dentro de uma classe filha
    protected string nome;
    public string corPelo;
    public int forca;

    //Ações = métodos
    public void ataque()
    {
        print("Ataquei");
    }

}

class Filha : Felino
{
    public void acessa()
    {
        nome = "Gato";
    }
}

I’ve looked for some answers but so far nothing works

asked Aug 19, 2020 at 17:57

ToDyToScAnO's user avatar

3

Unless a class is in a namespace, the class it in the ‘global namespace’. Add a namespace around your classes. I’m not saying this is the complete answer, but not using namespaces is a bad idea. Namespaces usually start with the name of your solution and will be placed there automatically when you create a new class.

Try this:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ToDyToScAnO // <-- This is a namespace
{
  public class modificadoracesso : MonoBehaviour
  {

    Felino gatoFase1; // criar objeto
    Felino gatoFase2;
    Filha fi;

    // Start is called before the first frame update
    void Start()
    {
        gatoFase1 = new Felino (); //objeto
        gatoFase2 = new Felino ();
        fi = new Filha();

        //gatoFase1.nome = "mark";
        gatoFase1.ataque();
        gatoFase1.corPelo = "Preto";
        gatoFase1.forca = 100;

        //gatoFase2.nome = "Zuck";
        gatoFase2.corPelo = "Marrom";
        gatoFase2.ataque();

        fi.acessa();

    }

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

class Felino : MonoBehaviour
{

    //Características = atributos
    //protected trabalha dentro a classe ou dentro de uma classe filha
    protected string nome;
    public string corPelo;
    public int forca;

    //Ações = métodos
    public void ataque()
    {
        print("Ataquei");
    }

}

 class Filha : Felino
 {
    public void acessa()
    {
        nome = "Gato";
    }
 }
}

answered Aug 19, 2020 at 18:48

Neil's user avatar

NeilNeil

10.6k2 gold badges28 silver badges53 bronze badges

0

This usually occurs when you drag and drop a script to another folder, while your text editor still has the script open. When you save the file in text editor, the file is re-created in old location, so you have a duplicate script for the moved script.

answered Jul 10, 2022 at 19:44

Emmanuel Mukombero's user avatar

It’s only because you have another script in your project with this name!
Maybe you accidentally duplicate it or something.

answered Oct 16, 2021 at 10:58

azin's user avatar

azinazin

113 bronze badges

Ребят, помогите пожалуйста. У меня казалось бы всего лишь 27 строчек кода, но откуда в 3 ошибки, не понятно… Вроде всё правильно на писал.
1 Ошибка CS0101: The namespace » already contains a definition for ‘Destroyable’
2 Ошибка CS0111: Type ‘Destroyable’ already defines a member called ‘Start’ with the same parameter types
3 Ошибка CS0111: Type ‘Destroyable’ already defines a member called ‘Update’ with the same parameter types

Мой код

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Destroyable : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

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

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            collision.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * 8f, ForceMode2D.Impulse);
            gameObject.GetComponentInParent<Enemy>().startDeath();
        }
    }
}

Помогите поправить скрипт поднятия патронов

Помогите поправить скрипт поднятия патронов

Выдаёт такие ошибки:
Assets/WeaponScripts/AmmoItem.cs(5,32): error CS1519: Unexpected symbol `;’ in class, struct, or interface member declaration
Assets/WeaponScripts/AmmoItem.cs(5,31): error CS1519: Unexpected symbol `test’ in class, struct, or interface member declaration
Assets/WeaponScripts/AmmoItem.cs(4,14): error CS0101: The namespace `global::’ already contains a definition for `AmmoItem’
в этом скрипте:

Используется csharp

using UnityEngine;
using System.Collections;

 
public class AmmoItem : MonoBehaviour {
    public RocketLauncher test;

     
    // Update is called once per frame
    void Update ()
    {
        GameObject player = GameObject.FindGameObjectWithTag(«Player»);
        if(Input.GetButtonDown(«Use»)&Vector3.Distance(transform.position, player.transform.position)<2)
        {
            test.CurCatrige += 1;
            Destroy(gameObject);
        }
    }
}

Подскажите как исправить, заранее благодарен

DARKANGL3600
UNец
 
Сообщения: 17
Зарегистрирован: 27 дек 2013, 19:01

Re: Помогите поправить скрипт поднятия патронов

Сообщение waruiyume 04 фев 2014, 17:01

Вы смотрите, какая ошибка самая «верхняя». На 4 строке «Assets/WeaponScripts/AmmoItem.cs(4,14): error CS0101: The namespace `global::’ already contains a definition for `AmmoItem», т.е. где-то такой класс/структура уже есть, Вы, либо, его удалите/переименуйте, либо перепишите.

Аватара пользователя
waruiyume
Адепт
 
Сообщения: 6059
Зарегистрирован: 30 окт 2010, 05:03
Откуда: Ростов на Дону


Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex [Bot] и гости: 24

Понравилась статья? Поделить с друзьями:
  • Unity выдает ошибку при установке
  • Unity выдает ошибку при запуске игры
  • Unity visual studio не показывает ошибки
  • Unity player dll ошибка что делать
  • Unity player dll ошибка геншин