Search Unity

I can´t find the error CS1022

Discussion in 'Scripting' started by Midnaplays123, Jan 18, 2021.

  1. Midnaplays123

    Midnaplays123

    Joined:
    Nov 30, 2020
    Posts:
    11
    So i have this Grounded script for my player and i can´t find the CS1022 Error.


    Code (CSharp):
    1.     GameObject Player; {
    2.     // Start is called before the first frame update
    3.     void Start()
    4.     {
    5.         Player = GameObject.transform.parent.GameObject;
    6.     }
    7.  
    8.     // Update is called once per frame
    9.     void Update()
    10.     {
    11.     }
    12.     private void OnCollisionEnter2D(Collision2D collision)
    13.     {
    14.         if (collision.collider.tag == ("Ground"))
    15.             Player.GetComponent<Move2D>().isGrounded = true;
    16.     }
    17.     private void OnCollisionExit2D(Collision2D collision)
    18.     {
    19.         if (collision.collider.tag == ("Ground"))
    20.             Player.GetComponent<Move2D>().isGrounded = false;
    21.         }
    22.    
    If anyone help me: pls help me :D
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    I can't either. What is error CS1022? I don't memorize error codes. Also, the error code usually points to a line, or a line close to the error.

    I do see you have an { after GameObject Player; Not sure if it's suppose to be connected to something, but it seems to be in an odd location.
     
    seejayjames likes this.
  3. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    Always search on the error. This one is "Type or namespace definition, or end-of-file expected" and is indeed caused by the extra { at the top. Understanding why this is happening is important, so be sure you're clear on that.

    Compiler Error CS1022 | Microsoft Docs