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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Unity Error CS1001 and CS1022

Discussion in 'Editor & General Support' started by CateByrer05, Nov 11, 2020.

  1. CateByrer05

    CateByrer05

    Joined:
    Nov 5, 2020
    Posts:
    3
    I am using Unity coding on a Macbook for an online class, it is a 2D UFO, but I was having trouble and got errors that I didn't know how to change or I would get more errors. The two errors I have left are (20,30) CS1001: Identifier expected and (21,2) CS1022: Type or namespace definition, or end-of-life-file expected. If anyone can help me I would appreciate it (and it looks weird because the Macbooks don't use the same editors and script for these are different).

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class PlayerController : MonoBehaviour {
    5. public float speed;
    6. private Rigidbody2D rb2d;
    7. void Start()
    8. {
    9. rb2d = GetComponent<Rigidbody2D> ();
    10. }
    11. void FixedUpdate()
    12. {
    13. float moveHorizontal = Input.GetAxis ("Horizontal");
    14. float moveVertical = Input.GetAxis ("Vertical");
    15. Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    16. rb2d.AddForce (movement * speed);
    17. }
    18. void OnTriggerEnter2D(Collider2D other);
    19. other.gameObject.CompareTag
    20. other.gameObject.SetActive (f);
    21. }}
     

    Attached Files:

  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Code (CSharp):
    1. other.gameObject.CompareTag
    Is a line that makes no sense and must be incorrect. I assume it was supposed to be part of an if statement (e.g. if (other.gameObject.CompareTag("Something")) ). Was this code is based on/copied from some tutorial? Double check that this line is correct.

    Visual Studio Code is available for Mac. Don't try to write code in the most basic text editor, or you will end up with unformatted and unreadable code (like in your screenshot).
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    Don't use TextEdit for editing code. It does all kinds of awful things to code like inserting "smart quotes" and the like.

    Use Visual Studio as recommended above, or if you really want to use a basic text editor at least use Sublime Text or something along those lines.

    Also please post your code with Code Tags because us forum-goers are weak and can't handle unformatted text like your TextEdit code.
     
  4. CateByrer05

    CateByrer05

    Joined:
    Nov 5, 2020
    Posts:
    3
    My computer is only allowed to use TextEdit. I am not able to use any other coding doc. It is a school computer with a lot of restrictions.
     
  5. CateByrer05

    CateByrer05

    Joined:
    Nov 5, 2020
    Posts:
    3
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class PlayerController : MonoBehaviour {
    5. public float speed;
    6. private Rigidbody2D rb2d;
    7. void Start()
    8. {
    9. rb2d = GetComponent<Rigidbody2D> ();
    10. }
    11.     void FixedUpdate()
    12. {
    13. float moveHorizontal = Input.GetAxis ("Horizontal");
    14. float moveVertical = Input.GetAxis ("Vertical");
    15. Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    16. rb2d.AddForce (movement * speed);
    17. }
    18. void OnTriggerEnter2D(Collider2D other);
    19. other.gameObject.CompareTag *Pickup*;
    20. other.gameObject.SetActive f;
    21. }}
     
  6. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    They allow Unity but not an IDE? That's a very strange limitation.

    I am going to assume you have copied this code from some sort of tutorial (since you did not answer this question earlier)

    On line 18, you need to replace the ; with a {

    Try this, for line 19 and 20:

    Code (CSharp):
    1. if (other.gameObject.CompareTag("Pickup"))
    2.   other.gameObject.SetActive(false);
    If it is still not working, go back and check the source code very carefully for any errors, wrong {'s, misplaced ;'s etc.
     
    PraetorBlue likes this.