Error cs0111 unity

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 {

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:

AssetsZombieScript.cs(5,14): error CS0101: The namespace » already contains a definition for ‘ZombieScript’

AssetsZombieScript.cs(12,10): error CS0111: Type ‘ZombieScript’
already defines a member called ‘Start’ with the same parameter types

AssetsZombieScript.cs(17,10): error CS0111: Type ‘ZombieScript’
already defines a member called ‘Update’ with the same parameter types

in advance, thank u <3

Rao Arman's user avatar

Rao Arman

1,1051 gold badge12 silver badges35 bronze badges

asked Jul 22, 2020 at 8:40

BelaruS coder's user avatar

4

A basic structure of a C# class looks like this:

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.

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. Therefore, kindly check if you have it defined somewhere else (within the same namespace) and if found it you’re good to go!

answered Jul 22, 2020 at 8:48

Zephyr's user avatar

ZephyrZephyr

3052 silver badges8 bronze badges

0

Код

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

public class PlayerMove : MonoBehaviour
{
    private Animator anim;
    private Rigidbody2D rb;
    private SpriteRenderer sprite;
    private bool faceUp;
    void Start()
    {
        anim = GetComponent<Animator>();
        sprite = GetComponent<SpriteRenderer>();
    }

    void Update()
    {
        if (input.GetKey(«w») || input.GetKey(«a») || input.GetKey(«s») || input.GetKey(«d»))
        {
            if (input.GetKey(«w»)){
                anim.SetBool(«FaceUp», true);
                anim.SetBool(«Walk», true);
            }
            if (input.GetKey(«s»)){
                anim.SetBool(«FaceUp», false);
                anim.SetBool(«Walk», true);
            }
            if (input.GetKey(«a»)){
                sprite.flipX = true;
                anim.SetBool(«Walk», true);
            }
            if (input.GetKey(«d»)){
                sprite.flipX = false;
                anim.SetBool(«Walk», true);
            }
        }else{
            anim.SetBool(«Walk», false);
        }
    }
}

Вообщем юнити жалуется что у меня ошибка CS0111.
Она выскакивает если класс содержит два объявления членов с одинаковыми именами и типами параметров.
Но я не могу их найти! Я или в глаза долблюсь, или просто глупый. Помогите вообщем) crazy

как бороться ?

using UnityEngine;
using System.Collections;

public class MoveByDisplay : MonoBehaviour
{
public Rigidbody2D rb2d;
public float playerSpeed;
public float jumpPower;
public int directionInput;
public bool groundCheck;
public bool facingRight = true;
public int jumpsLimit;
public int jumpsDone;

void Start()
{
rb2d = GetComponent();

}

void Update()
{
if ((directionInput < 0) && (facingRight))
{
Flip();
}

if ((directionInput > 0) && (!facingRight))
{
Flip();
}
groundCheck = true;
}

void FixedUpdate()
{
rb2d.velocity = new Vector2(playerSpeed * directionInput, rb2d.velocity.y);
}

public void Move(int InputAxis)
{

directionInput = InputAxis;

}

public void Jump()
{
rb2d.AddForce(Vector2.up * jumpPower * playerSpeed);
}

void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}

public void Jump()
{
if (jumpsDone < jumpsLimit)
{
rb2d.AddForce(Vector2.up * jumpPower * playerSpeed);
jumpsdone++;
}
}
}

this is my code and i get the same problem do you have solutions?

using UnityEngine;

[RequireComponent(typeof(SpriteRenderer))]
public class Invader : MonoBehaviour
{
public SpriteRenderer spriteRenderer { get; private set; }
public Sprite[] animationSprites = new Sprite[0];
public float animationTime = 1f;
public int animationFrame { get; private set; }
public int score = 10;
public System.Action<invader> killed;

private void Awake()
{
spriteRenderer = GetComponent<spriterenderer>();
spriteRenderer.sprite = animationSprites[0];
}

private void Start()
{
InvokeRepeating(nameof(AnimateSprite), animationTime, animationTime);
}

private void AnimateSprite()
{
animationFrame++;

// Loop back to the start if the animation frame exceeds the length
if (animationFrame >= animationSprites.Length) {
animationFrame = 0;
}

spriteRenderer.sprite = animationSprites[animationFrame];
}

}

Понравилась статья? Поделить с друзьями:
  • Error cs0103 unity
  • Error cs0103 the name thread does not exist in the current context
  • Error cs0103 the name scenemanager does not exist in the current context
  • Error cs0103 the name scenemanagement does not exist in the current context
  • Error cs0103 the name math does not exist in the current context