Search Unity

CS1022

Discussion in 'Scripting' started by Actionjaxon777, Apr 19, 2021.

  1. Actionjaxon777

    Actionjaxon777

    Joined:
    Feb 25, 2021
    Posts:
    8
    Hello. im new to scripting and cant figure this out. It keeps giving the CS1022 error at the last line.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Photon
    4. {
    5.     public class MonoBehaviour : MonoBehaviour{
    6.         }
    7.     }
    8. }
     
    Last edited: Apr 19, 2021
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    A bunch of problems here:
    • Do not name your script class "MonoBehaviour". That is a built in Unity type that your script should derive from, but you should not name your script that. Name it something descriptive. "PlayerMovement" or "PlatformControl".
    • Do not put your script in the "Photon" namespace. That is the namespace that the Photon networking framework uses for its classes. Putting your script in that namespace will just cause confusion. It is probably best for now to simply not use a namespace at all.
    • Your script's class name and the filename must match.
      public class PlayerMovement : MonoBehaviour
      should live in a file named "PlayerMovement.cs".
    • You have mismatched curly braces. Every '{' must have a matching '}'. In your case, you have only two '{'s but three '}'. So there is a mismatch.
     
    Vryken and bobisgod234 like this.
  3. Everything @PraetorBlue said plus:
     
    StarManta and PraetorBlue like this.
  4. Actionjaxon777

    Actionjaxon777

    Joined:
    Feb 25, 2021
    Posts:
    8
    im confused
     
  5. Well, if you want some help with that, you will need to do a better job explaining why are you confused and with what exactly, we aren't mind-readers (sadly).
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Again, remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all.

    The important parts of an error message are:
    - the description of the error itself
    - the file it occurred in
    - the line number and character position.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855
     
  7. Zapp36

    Zapp36

    Joined:
    May 18, 2021
    Posts:
    13
    can you please help me with my error? {Assets\PlayerMovement.cs(1,1): error CS1022: Type or namespace definition, or end-of-file expected}
    Code (csharp):
    1.  
    2. ;using UnityEngine;
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     [Header("Movement")]
    6.     public float PlayerMovementSpeed = 6f;
    7.     float horizonalMovement;
    8.     float verticalMovement;
    9.     Vector3 moveDirection;
    10.     Rigidbody rb;
    11.     private void start()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.         rb.freezeRotation = true;
    15.     }
    16.     private void update()
    17.     {
    18.        MyInput();
    19.     }
    20.     void MyInput()
    21.     {
    22.        horizonalMovement = Input.GetAxisRaw("Horizontal");
    23.        verticalMovement = Input.GetAxisRaw("Vertical");
    24.        moveDirection = transform.forward * verticalMovement + transform.right * horizonalMovement;
    25.     }
    26.    
    27.     private void FixedUpdate()
    28.     {
    29.        MovePlayer();
    30.     }
    31.     void MovePlayer()
    32.     {
    33.        rb.AddForce(moveDirection.normalized * PlayerMovementSpeed, ForeceMode.Acceleration);
    34.     }
    35. }
     
  8. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    497
    The error is telling you that your problem is on the first line at the first character. So looking at that, we can see this line:
    Code (csharp):
    1. ;using UnityEngine;
    It should be pretty obvious that a
    ;
    should only be at the end of the line (especially if you look at any other script and how the
    using
    statements are in those).
    Remove the
    ;
    from the start of the line.
    At a glance though you will still have issues with this as your
    start()
    and
    update()
    methods are wrong. C# is a case-sensitive language, and as such these methods should be
    Start()
    and
    Update()