Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assets/Game/Script/Character.cs(8,24): error CS1003: Syntax error, ',' expected

Discussion in 'Getting Started' started by UGIStudio, Nov 8, 2023.

  1. UGIStudio

    UGIStudio

    Joined:
    Oct 16, 2019
    Posts:
    4
    Hi guys! I am new to Unity, studying how to develop my Pet project. I have wrote this code according to the tutorial but received an error

    Assets/Game/Script/Character.cs(8,24): error CS1003: Syntax error, ',' expected

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Character : MonoBehaviour
    6. {
    7. private CharacterController _cc;
    8. public float MoveSpeed - 5f;
    9. private Vector3 _movementVelocity;
    10. private PlayerInput _playerInput;
    11.  
    12. private void Awake() {
    13.     _cc - GetComponent<CharacterController>();
    14.     _playerInput - GetComponent<PlayerInput>();
    15. }
    16.  
    17. private void CalculatePlayerMovement(){
    18.     _movementVelocity.Set(_playerInput.HorizontalInput,0f,_playerInput.VerticalInput);
    19.     _movementVelocity.Normalize();
    20.     _movementVelocity - Quaternion.Euler(0,-45f,0) * _movementVelocity;
    21.     _movementVelocity *- MoveSpeed * Time.deltaTime;
    22. }
    23.  
    24.     private void FixedUpdate(){
    25.         CalculatePlayerMovement();
    26.         _cc.Move(_movementVelocity);
    27.     }
    28. }
    I understand that i have to look at line 8 column 24 - but i don't understand how to fix the issue.
    Please help me
     
  2. Well, here is the code:
    public float MoveSpeed - 5f;

    Now explain to me please, what did you want to do here and then explain to me what this line of code actually do and then spot the difference.
     
  3. Guardian865

    Guardian865

    Joined:
    Nov 9, 2023
    Posts:
    5
    Code (CSharp):
    1. public float MoveSpeed = -5f;
    you missed '=' symbol.
     
  4. UGIStudio

    UGIStudio

    Joined:
    Oct 16, 2019
    Posts:
    4
    In this code, i am defining how fast the player should move, so i am creating a public float MoveSpeed with the default value 5f.
    I am setting MoveSpeed public, because would like to change it from the inspector in Unity.

    So you mean that i have change '-' on the '=' ?

    If i just change - public float MoveSpeed = 5f;

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Character : MonoBehaviour
    6. {
    7. private CharacterController _cc;
    8. public float MoveSpeed = 5f;
    9. private Vector3 _movementVelocity;
    10. private PlayerInput _playerInput;
    11.  
    12.  
    13. private void Awake() {
    14.     _cc - GetComponent<CharacterController>();
    15.     _playerInput - GetComponent<PlayerInput>();
    16. }
    17.  
    18. private void CalculatePlayerMovement(){
    19.     _movementVelocity.Set(_playerInput.HorizontalInput,0f,_playerInput.VerticalInput);
    20.     _movementVelocity.Normalize();
    21.     _movementVelocity - Quaternion.Euler(0,-45f,0) * _movementVelocity;
    22.     _movementVelocity *- MoveSpeed * Time.deltaTime;
    23. }
    24.  
    25.     private void FixedUpdate(){
    26.         CalculatePlayerMovement();
    27.         _cc.Move(_movementVelocity);
    28.     }
    29. }
    I receive many other issues.

    I am moving on the video tutorial from Udemy and can't get what i am doing wrong because my code looks exatly the same as in the video tutorial.
     

    Attached Files:

  5. UGIStudio

    UGIStudio

    Joined:
    Oct 16, 2019
    Posts:
    4
    I have fixed all issues in this code and wrote comments. Code works - character moves on the location.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Character : MonoBehaviour
    6. {
    7.     private CharacterController _cc; // Reference to the CharacterController component.
    8.     public float MoveSpeed = 5f; // Movement speed for the character.
    9.     private Vector3 _movementVelocity; // The velocity of the character's movement.
    10.     private PlayerInput _playerInput; // Reference to the PlayerInput component.
    11.  
    12.     private void Awake() {
    13.         // Get references to components when the script starts.
    14.         _cc = GetComponent<CharacterController>();
    15.         _playerInput = GetComponent<PlayerInput>();
    16.     }
    17.  
    18.     private void CalculatePlayerMovement() {
    19.         // Get input data from the player.
    20.         _movementVelocity.Set(_playerInput.HorizontalInput, 0f, _playerInput.VerticalInput);
    21.         _movementVelocity.Normalize();
    22.  
    23.         // Rotate the player's movement by 45 degrees.
    24.         _movementVelocity = Quaternion.Euler(0, -45f, 0) * _movementVelocity;
    25.  
    26.         // Multiply the vector by speed and time to calculate movement in FixedUpdate.
    27.         _movementVelocity *= MoveSpeed * Time.deltaTime;
    28.     }
    29.  
    30.     private void FixedUpdate(){
    31.         // Call the function to calculate movement and move the character.
    32.         CalculatePlayerMovement();
    33.         _cc.Move(_movementVelocity);
    34.     }
    35. }
    Thank you for the help. Have a nice day!
     
  6. I guarantee you it is not true. You just fixed your first issue, now go through your error messages and fix the rest. I doubt that on Udemy they would mix up
    =
    with
    -
    . In fact, I challenge you to stop the tutorial, go back and compare your lines one by one and fix all the issues you mistakenly typed wrong. You only can be a programmer if you can type precisely. minus doesn't mean equal and vice versa. And it will be a bit harder when you don't just have to copy code like a robot but you need to come up with the code to achieve whatever is it you want to do. So practice and don't give up.
     
    UGIStudio likes this.
  7. UGIStudio

    UGIStudio

    Joined:
    Oct 16, 2019
    Posts:
    4
    Thank you very much. Totally agree. I will practice!