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

Assets\Move2d.cs(25,2): error CS1513: } expected

Discussion in '2D' started by Atskas, Jul 22, 2020.

?

new to posting,it makes me add a poll

  1. bruh

    1 vote(s)
    50.0%
  2. bruh

    1 vote(s)
    50.0%
Thread Status:
Not open for further replies.
  1. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    So i've been stuck lately. Ive been following this tutorial for my playermovement but got stuck.
    (
    )

    Here is the code.(pretty sure the problem is on line 25,i dont get it)


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Move2d : MonoBehaviour {
    4.     public float moveSpeed = 5f;
    5.     // Start is called before the first frame update
    6.     void Start() {
    7.         {
    8.  
    9.         }
    10.  
    11.         // Update is called once per frame
    12.         void Update() {
    13.         Jump();
    14.     {
    15.         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
    16.         transform.position += movement * Time.deltaTime * moveSpeed;
    17.     }
    18.  
    19.     void Jump(){
    20.         if (Input.GetButtonDown("Jump")){
    21.             gameObject.GetComponent<RigidBody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
    22.             }
    23.  
    24.         }
    25. }
     
  2. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    The error message says what is expected and where, you just have to read it.
     
  3. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    Code (CSharp):
    1. using UnityEngine;
    2. public class Move2d : MonoBehaviour
    3. {
    4.     public float moveSpeed = 5f;
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.     }
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         Jump();
    13.    
    14.         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
    15.         transform.position += movement * Time.deltaTime * moveSpeed;
    16.     }
    17.     void Jump()
    18.     {
    19.         if (Input.GetButtonDown("Jump"))
    20.             gameObject.GetComponent<RigidBody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
    21.     }
    22. }

    You had too many brackets....
     
  4. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    I tried this and got this error even tho i have a RigidBody2D

    Assets\Move2d.cs(20,37): error CS0246: The type or namespace name 'RigidBody2D' could not be found (are you missing a using directive or an assembly reference?)
     
  5. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7

    Fixed it. it was Rigidbody 2D not RigidBody2d
     
  6. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    Uh so,i continued the tutorial and now this happened

    Assets\Grounded.cs(30,1): error CS1022: Type or namespace definition, or end-of-file expected

    Grounded script:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Grounded : MonoBehaviour {
    4.     GameObject Player;
    5.  
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         Player = gameObject.transform.parent.gameObject;
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.  
    16.     }
    17.     private void OnCollisionEnter2D(Collision2D collision)
    18.     {
    19.         if (collision.collider.tag == "Ground")
    20.             Player.GetComponent<Move2D>().isGrounded == true;
    21.     }
    22.  
    23.     private void OnCollisionExit2D(Collision2D collision)
    24.          if (collision.collider.tag == "Ground")
    25.     {
    26.         Player.GetComponent<Move2D>().isGrounded == false;;
    27.     }
    28. }
    Move2d:


    Code (CSharp):
    1. using UnityEngine;
    2. public class Move2d : MonoBehaviour
    3. {
    4.     public float moveSpeed = 5f;
    5.     public bool isGrounded = false;
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.     }
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.         Jump();
    14.  
    15.         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
    16.         transform.position += movement * Time.deltaTime * moveSpeed;
    17.     }
    18.     void Jump()
    19.     {
    20.         if (Input.GetButtonDown("Jump") && isGrounded == true)
    21.             gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
    22.     }
    23. }
     
  7. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Grounded script refers to Move2D. You have named your script/class Move2d.
     
    Last edited: Jul 23, 2020
  8. Atskas

    Atskas

    Joined:
    Jul 7, 2020
    Posts:
    7
    Assets\Grounded.cs(28,1): error CS1022: Type or namespace definition, or end-of-file expected


    Wtf
     
  9. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Grounded script:

    Line 20: Player.GetComponent<Move2D>().isGrounded == true;

    Should read: Player.GetComponent<Move2D>().isGrounded = true;

    Line 26: Player.GetComponent<Move2D>().isGrounded == false;;

    Should read: Player.GetComponent<Move2D>().isGrounded = false;

    Also, check your curly braces around and within your if statements.

    Time in video = 9:07
     
    Last edited: Jul 23, 2020
  10. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Not related to your topic, but you don't have to include a poll in your thread.
    Just leave the form fields for the poll empty when creating a thread, and it won't be included.
     
  11. Falconteam

    Falconteam

    Joined:
    Oct 23, 2022
    Posts:
    1
    Same thing happened to me on line 25
     

    Attached Files:

  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Then the same thing applies to you: GO FIX YOUR TYPING MISTAKES!

    Here is how:

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
     
Thread Status:
Not open for further replies.