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. Dismiss Notice

Question I need help with this error!

Discussion in 'Scripting' started by Alex_8000, May 8, 2021.

  1. Alex_8000

    Alex_8000

    Joined:
    May 8, 2021
    Posts:
    2
    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:





    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using Enemy;
    7.  
    8. namespace MenuButtonScript { namespace MenuButtonScript {;
    9.  
    10.  
    11. public class MenübuttonScript : MonoBehaviour
    12.         {
    13.             // Start is called before the first frame update
    14.             void Start();
    15.  
    16.  
    17.             public int klick;
    18.  
    19.             bool isClicked;
    20.  
    21.  
    22.             int klick = (0);
    23.  
    24.             bool isClicked = false;
    25.  
    26.         }
    27.  
    28.  
    29.         // Update is called once per frame
    30.         void Update()
    31.         {
    32.  
    33.             // clicked?
    34.  
    35.             if (Input.GetMouseButtonDown(0)) ;
    36.  
    37.             { isClicked = true;
    38.             }
    39.  
    40.             if (Input.GetmouseButtonUp(0)) ;
    41.  
    42.             { isClicked = false;
    43.             }
    44.  
    45.  
    46.            
    47.  
    48.             if (klick == 0 && isClicked == true) ;
    49.  
    50.             { klick = 1;
    51.             };
    52.  
    53.  
    54.  
    55.  
    56.  
    57.             if (klick == 1 && isClicked == true) ;
    58.             { klick = 0;
    59.             };
    60.  
    61.         }
    62.     }
    63. }
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,916
    - 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
     
  3. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    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".
     
    Kurt-Dekker likes this.
  4. Alex_8000

    Alex_8000

    Joined:
    May 8, 2021
    Posts:
    2
    It works now! Thank you for your help.