Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

i need help i keep getting errors

Discussion in 'Scripting' started by itspicklerickandmorty, Apr 7, 2020.

  1. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    the errors are error 'CS0111: Type 'Mouselook' already defines a member called 'Update' with the same parameter types' x2 and
    The namespace '<global namespace>' already contains a definition for 'Mouselook' is ther anything wrong with my code?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mouselook : MonoBehaviour
    6. {
    7.  
    8.     public float mouseSensitivity = 100f;
    9.  
    10.     public Transform playerBody;
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.        
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    21.         float mouseY = input.GetAxis("mouse Y") * mouseSensitivity * Time.deltaTime;
    22.  
    23.         playerBody.Rotate(Vector3.up * mouseX);
    24.     }
    25. }
    26.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    You created a class with a name that already exists.
    Rename it to something else and dont forget to rename the file to the same name as the class.
     
    Joe-Censored likes this.
  3. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    what do I change and where do i change it
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Your error literally tells you that 'Mouselook' already exists. So you have that name twice. Either you created a class with the same name twice, or Unity or one of the assets you imported also uses a 'Mouselook'. So what do you rename? Mouselook, of course. And since class- and filename have to match, you have to rename the file as well.
     
    Kurt-Dekker and Joe-Censored like this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    @Yoreki already gave the most direct solution. Though this is also a reason namespaces exist. A bit of an advanced topic for a beginner, but might be worth a google of "C# namespace" to learn something new.