Error CS 0111

Hello,
can anyone help me, I have the error CS 0111!
Unity says:
Assets/Scripts/Vehicles/Giftszene.cs(28,10): error CS0111: Type ‘Giftszene’ already defines a member called ‘Update’ with the same parameter types

My Script:

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

public class Giftszene : MonoBehaviour
{
    public GameObject player;
    public GameObject playercam;
    public GameObject mehl;
    public GameObject salz;
    public GameObject hefe;
    public GameObject gift;
    public GameObject kitchencam;
    public GameObject roomcam;

    void Update()
    {
            if (Input.GetKeyDown(KeyCode.M));
            {
                this.gameObject.GetComponent<BoxCollider>().enabled = false;
                kitchencam.SetActive(true);
                player.SetActive(false);
                playercam.setActive(false);
                return (null);
            }
    }

    void Update()
    {
         If (Input.GetKeyDown(KeyCode.F));
         {
            mehl.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.J))
         {
            salz.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.K))
         {
            hefe.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.H));
         {
            gift.setActive(false);
         }
        if (Input.GetKeyDown(KeyCode.Enter))
        {
            kitchencam.setActive(false);
            roomcam.setActive(true);
            yield return new WaitForSeconds(4);
            roomcam.setActive(false);
            thePlayer.setActive(true);
            playercam.setActive(true);
        }
    }
}

It’s very clear. You have two Update methods. You can only have one.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Ok, thank you, but if I remove one Update method, than it also didn’t work

This is a useless assessment. What happened? What did you change the code to? Did you get an error? What error?

I got 15 Errors, unity says:

Assets/Scripts/Vehicles/Giftszene.cs(25,23): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(26,13): error CS1622: Cannot return a value from an iterator. Use the yield return statement to return a value, or yield break to end the iteration.

Assets/Scripts/Vehicles/Giftszene.cs(26,13): error CS0127: Since ‘Giftszene.Update()’ returns void, a return keyword must not be followed by an object expression

Assets/Scripts/Vehicles/Giftszene.cs(18,10): error CS1624: The body of ‘Giftszene.Update()’ cannot be an iterator block because ‘void’ is not an iterator interface type

Assets/Scripts/Vehicles/Giftszene.cs(18,10): error CS1624: The body of ‘Giftszene.Update()’ cannot be an iterator block because ‘void’ is not an iterator interface type

Assets/Scripts/Vehicles/Giftszene.cs(28,10): error CS0103: The name ‘If’ does not exist in the current context

Assets/Scripts/Vehicles/Giftszene.cs(30,18): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(34,18): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(38,18): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(42,18): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(44,38): error CS0117: ‘KeyCode’ does not contain a definition for ‘Enter’

Assets/Scripts/Vehicles/Giftszene.cs(46,24): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(47,21): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(49,21): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/Vehicles/Giftszene.cs(50,13): error CS0103: The name ‘thePlayer’ does not exist in the current context

Assets/Scripts/Vehicles/Giftszene.cs(51,23): error CS1061: ‘GameObject’ does not contain a definition for ‘setActive’ and no accessible extension method ‘setActive’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

I changed the script to the following:

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

public class Giftszene : MonoBehaviour
{
    public GameObject player;
    public GameObject playercam;
    public GameObject mehl;
    public GameObject salz;
    public GameObject hefe;
    public GameObject gift;
    public GameObject kitchencam;
    public GameObject roomcam;



    void Update()
    {
         if (Input.GetKeyDown(KeyCode.M));
         {
            this.gameObject.GetComponent<BoxCollider>().enabled = false;
            kitchencam.SetActive(true);
            player.SetActive(false);
            playercam.setActive(false);
            return (null);
         }
         If (Input.GetKeyDown(KeyCode.F));
         {
            mehl.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.J))
         {
            salz.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.K))
         {
            hefe.setActive(false);
         }
         if (Input.GetKeyDown(KeyCode.H));
         {
            gift.setActive(false);
         }
        if (Input.GetKeyDown(KeyCode.Enter))
        {
            kitchencam.setActive(false);
            roomcam.setActive(true);
            yield return new WaitForSeconds(4);
            roomcam.setActive(false);
            thePlayer.setActive(true);
            playercam.setActive(true);
        }
    }
}

90% of those errors are just you miscaptalizing SetActive and misspelling variable names.

I have this “error CS0111: Type ‘Player’ already defines a member called ‘Update’ with the same parameter types” error and this is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{

// Start is called before the first frame update

// Update is called once per frame
void Update()
{
float vertical = Input.GetAxis(“Vertical”);
Vector2 position = transform.position;
position.y = position.y + 4.5f * vertical * Time.deltaTime;
transform.position = position;
}
}

Hello

Maybe you habe anonther class with the Same name?

Christoph