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

HELP WITH SCRIPT

Discussion in 'Scripting' started by Chrisbroishere, May 17, 2021.

  1. Chrisbroishere

    Chrisbroishere

    Joined:
    May 16, 2021
    Posts:
    4
    help unity shows error CS1002 and the only way to solve it is to delete the script thats the script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour {
    public float movementSpeed
    public Rigidbody2D rb;

    float mx;

    private void Update() {
    mx = Input.GetAxisRaw("Horizontal");
    }

    private void FixedUpdate() {
    Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y)

    rb.velocity = movement
    }
    }
    HAVE I DONE SOMETHING WRONG IF YES PLEASE LET ME KNOW
     
  2. taskmagee

    taskmagee

    Joined:
    Sep 16, 2018
    Posts:
    31
    Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y)

    You're missing a ; at the end
    Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
     
  3. Chrisbroishere

    Chrisbroishere

    Joined:
    May 16, 2021
    Posts:
    4
    thanks for anwesering , I changed it but I still have the same problem
     
  4. taskmagee

    taskmagee

    Joined:
    Sep 16, 2018
    Posts:
    31
    You have the same issue with this line

    Code (CSharp):
    1. rb.velocity = movement;
    Make sure to closely check you're code. You can also double click the error in the console window and it should highlight the line in your code with the error.
     
  5. Chrisbroishere

    Chrisbroishere

    Joined:
    May 16, 2021
    Posts:
    4
    It worked, thank you some much for your help!
     
  6. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    If you actually read the error message it tells really useful information, it would tell you what script, line and column the error is on, I can guarantee you it also told you what you are missing and even if you didn't understand, you could've got some key words and done some research and would've got an answer in a matter of seconds, also when posting code snippets always use code tags!
     
    bobisgod234 likes this.