Error cs0101 unity

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

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



Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error creating session парус 10
  • Error creating remote thread code 0 advor
  • Error creating registry key hkey local machine
  • Error creating project xsrf check failed
  • Error creating process не удается найти указанный файл directx

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии