Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Error cs103

Discussion in 'Scripting' started by Hughboy36, Nov 17, 2020.

  1. Hughboy36

    Hughboy36

    Joined:
    Nov 17, 2020
    Posts:
    3
    I got the error Assets\PlayerController.cs(6,46): error CS1003: Syntax error, ',' expected and I don't know what to do.

    Here is my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class PlayerController : MonoBehaviour;{

    public float speed = 0;

    private Rigidbody rb;
    private float movementX;
    private float movementY;


    void Start(){
    rb = GetComponent<Rigidbody>();
    }


    void OnMove(InputValue movementValue){
    Vector2 movmentVector = movementValue.Get<Vector2>();

    movementX = movementVector.X;
    movementY = movementVector.Y;
    }
    void FixedUpdate(){
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);

    rb.AddForce(movement * speed);
    }

    }
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    528
    delete ;

    from this part

    Code (CSharp):
    1. MonoBehaviour;{
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    4,805
    Please use Code Tags in the future on the forums to make your code more reasonable.

    First step is look at the error. Note the line number and column number of the error in parentheses:
    Assets\PlayerController.cs(6,46): error CS1003: Syntax error, ',' expected


    Let's look at line 6:
    Code (CSharp):
    1. public class PlayerController : MonoBehaviour;{
    Ah there's your problem, a stray semicolon!
    ;
    Delete that.
     
    matkoniecz likes this.
  4. Hughboy36

    Hughboy36

    Joined:
    Nov 17, 2020
    Posts:
    3
    I have a new error
    Assets\PlayerController.cs(23,17): error CS0103: The name 'movementVector' does not exist in the current context

    Here is my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class PlayerController : MonoBehaviour{

    public float speed = 0;

    private Rigidbody rb;
    private float movementX;
    private float movementY;


    void Start(){
    rb = GetComponent<Rigidbody>();
    }


    void OnMove(InputValue movementValue){
    Vector2 movmentVector = movementValue.Get<Vector2>();

    movementX = movementVector.X;
    movementY = movementVector.Y;
    }
    void FixedUpdate(){
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);

    rb.AddForce(movement * speed);
    }

    }
     
  5. Hughboy36

    Hughboy36

    Joined:
    Nov 17, 2020
    Posts:
    3
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    4,805
    Double check that the spelling and capitalization of your variables are consistent throughout your code. You can't just be close, everything has to be spelled and capitalized exactly right, or your code cannot be compiled.
     
  7. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    734
    Please use code tags, you were asked earlier to do this and you are still not using them for some reason.

    You misspelt "movementVector" on this line:

    Code (CSharp):
    1. Vector2 movmentVector = movementValue.Get<Vector2>();
     
  8. felixschneider14

    felixschneider14

    Joined:
    Jan 14, 2021
    Posts:
    1
    I have the same problem here is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6.  
    7. public class PlayerController : MonoBehaviour
    8. {
    9.     private Rigidbody rb;
    10.     private float movementX;
    11.     private float movementY;
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         rb = GetComponent<Rigidbody>();
    16.  
    17.     }
    18.  
    19.  
    20.     void OnMove(InputValue movementValue)
    21.     {
    22.         Vector2 movementVector = movementValue.Get<Vector2>();
    23.  
    24.         movementX = movementVector.x;
    25.         movementY = movementVector.y;
    26.     }
    27.  
    28.     void FixedUpdate()
    29.     {
    30.         Vector3 movement = new Vector3(movementX, 0.0f, movementY);
    31.  
    32.         rb.AddForce(movementVector);
    33.     }
    34. }
    35.  
    thank you for thinking and helping
     
    Last edited: Jan 14, 2021
unityunity