I need help with this error!

Hi, I need help with this error:

Assets\Scenes\Menubutton Script.cs(6,58): error CS1022: Type or namespace definition, or end-of-file expected

I am new in Unity and C# and I can’t fix this error. There is my script:

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

namespace MenuButtonScript { namespace MenuButtonScript {;


public class MenübuttonScript : MonoBehaviour
        {
            // Start is called before the first frame update
            void Start();


            public int klick;

            bool isClicked;


            int klick = (0);

            bool isClicked = false;

        }


        // Update is called once per frame
        void Update()
        {

            // clicked?

            if (Input.GetMouseButtonDown(0)) ;

            { isClicked = true;
            }

            if (Input.GetmouseButtonUp(0)) ;

            { isClicked = false;
            }


            

            if (klick == 0 && isClicked == true) ;

            { klick = 1;
            };





            if (klick == 1 && isClicked == true) ;
            { klick = 0;
            };

        }
    }
}
  • rename the file to MenuButtonScript.cs
  • rename your class to MenuButtonScript
  • replace the 8th line from namespace MenuButtonScript { namespace MenuButtonScript {; to namespace MyButtonMenuScript { you can change it later to whatever you like
  • delete the 14th line void Start();
  • delete the 26th line }
  • delete the ; in the 26th, 40th, 48th, 51st, 57th, 59th lines

Check out some tutorials about the basic C# syntax:
https://www.tutorialspoint.com/csharp/csharp_program_structure.htm

As Lurking-Ninja points out your syntax is pretty “off”.
German “Umlaute” (ä, ö, ü) are not allowed and should be avoided generally in computer usage (file/folder names).
After a method declaration (void Start() ; ) is no semicolon as well as after an if (if (klick == 1 && isClicked == true) ; )
Your variable declarations are inside of Start and local to this method. You probably want them in your class.
Your namespace declaration is wrong too.
Your indentation and brackets ( {} )look odd.
Closing brackets are not ended with semicolons ( }; ). (Exception: enum declaration).

I can say with much confidence that I have never seen such a “mess” and so much errors in so little code before. It’s totally ok to start somewhere but this clearly shows you have not done your “homework” and learned the C# language.

Programming is done in a certain syntax so the compiler understands it and can properly transform your code into machine instructions. You HAVE to learn this syntax. I suggest rookies to learn C# programming OUTSIDE of Unity as it seems easier to me. Unity adds some additional “bloat” and can be more confusing. A good resource to start is the free C# Yellow Book by Rob Miles. Once your learned C# THEN start learning Unity. The forum is not a place to fix all your syntax errors and other errors like null reference exception etc. So learn this stuff properly before you attempt anything “useful”.

1 Like

It works now! Thank you for your help.