Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

the namespace global already contains a definition for

Discussion in '2D' started by gabrisimas, May 7, 2019.

  1. gabrisimas

    gabrisimas

    Joined:
    May 7, 2019
    Posts:
    1
    im in unity 2018.2.2if1 and i started to code in a few months ago
    this is my code but everytime that i play the game the message "the namespace global already contains a definition for" and i don´t known where´s my mistake
    can someone help me pls??




    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;

    public class Samus : MonoBehaviour {

    public float velocity;
    public float jumpPower;
    public bool isGround;
    public float health;
    public string nomeproxscena;
    public Scrollbar barrinha;


    // Referencias
    public Transform groundCheck;
    public LayerMask groundMask;

    // Use this for initialization
    void Start () {
    health = 100;

    }

    // Update is called once per frame
    void Update () {
    TryMovement();
    UpdateIsGround();
    TryJump ();
    verificarSeMorreu();
    barrinha.size = health / 100;
    }

    void TryMovement() {
    if(Input.GetKey (KeyCode.D) == true) {
    this.transform.Translate (Vector2.right * Time.deltaTime * velocity);
    }
    if(Input.GetKey (KeyCode.A) == true) {
    this.transform.Translate (Vector2.left * Time.deltaTime * velocity);
    }
    }

    void UpdateIsGround () {
    isGround = Physics2D.OverlapCircle (groundCheck.position,0.02f, groundMask);
    }

    void TryJump() {
    if((Input.GetKeyUp (KeyCode.W) || Input.GetKeyDown (KeyCode.Space) == true) && isGround == true) {
    this.GetComponent <Rigidbody2D> ().AddForce (Vector2.up * jumpPower);
    }
    }



    private void OnCollisionEnter2D(Collision2D collision)
    {
    if (collision.gameObject.tag == "Finish")
    {
    //SceneManager.LoadScene(nomeproxscena);
    SceneManager.LoadScene("Menu");
    }
    if (collision.gameObject.tag == "Void")
    {
    //SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    SceneManager.LoadScene("GameOver");
    }
    if (collision.gameObject.tag == "Bullet")
    {
    Destroy(collision.gameObject);
    health -= 50;
    }
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
    if (collision.gameObject.tag == "Enemy")
    {
    health -= 1;
    }
    }
    void verificarSeMorreu()
    {
    if (health <= 0)
    {
    SceneManager.LoadScene("GameOver");
    }
    }
    void UpdateAnimaton () {
    if (Input.GetKey(KeyCode.D) == true) {
    this.GetComponent <Animator> ().SetBool ("walking",true);
    this.transform.localScale = new Vector3 (1 , 1 , 1);
    } else if (Input.GetKey(KeyCode.A) == true) if (Input.GetKey(KeyCode.D) == true) {
    this.GetComponent <Animator> ().SetBool ("walking",true);
    this.transform.localScale = new Vector3 (-1 , 1 , 1);
    } else {
    this.GetComponent <Animator> ().SetBool ("walking" , false);
    }
    }
    }
     
  2. zioth

    zioth

    Joined:
    Jan 9, 2019
    Posts:
    103
    All it says is, "the namespace global already contains a definition for?" There's no additional word after "for?" If there is, that should tell you what your problem is.

    Either way, check the 3rd party libraries you're using. They might both declare a class or a global variable with the same name. or your class above, "Samus," might exist somewhere else in your project.

    Also, please use code blocks when posting here. Your code is very hard to read otherwise. You can create code blocks using the "code" icons in the editor toolbar when you're writing a post.
     
  3. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    65
    Are you sure you don't have two scripts with the same name? Or two scripts with the same class name at the top?