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); } }
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): public class PlayerController : MonoBehaviour;{ Ah there's your problem, a stray semicolon! ; Delete that.
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); } }
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.
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): Vector2 movmentVector = movementValue.Get<Vector2>();
I have the same problem here is my code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class PlayerController : MonoBehaviour { private Rigidbody rb; private float movementX; private float movementY; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); } void OnMove(InputValue movementValue) { Vector2 movementVector = movementValue.Get<Vector2>(); movementX = movementVector.x; movementY = movementVector.y; } void FixedUpdate() { Vector3 movement = new Vector3(movementX, 0.0f, movementY); rb.AddForce(movementVector); } } thank you for thinking and helping