C# unity error: Syntax error, ',' expected

Viewed 45

The full error code is: Assets\Scripts\CharacterMovementController.cs(31,52): error CS1003: Syntax error, ',' expected

I cant for the life of me figure out where the syntax error is so I'm starting to worry its something else that's being read as a syntax error

Here's the code:

using UnityEngine;

public class CharacterMovementController : MonoBehaviour
{
    public float moveSpeed = 1;
    public float jumpForce = 1;
    public int jumpNumber = 1;
    private int jumpNumberT;

    private Rigidbody2D _rigidbody;
    private Collider2D groundCheck;

    void Start()
    {
        _rigidbody = GetComponent<Rigidbody2D>();
        groundCheck = transform.Find("GroundCheck").GetComponent<Collider2D>();
    }

    
    void Update()
    {
        var movement = Input.GetAxis("Horizontal");
        transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * moveSpeed;

        if(Input.GetButtonDown("Jump") && jumpNumberT > 0){
            _rigidbody.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
            jumpNumberT = jumpNumber - 1;
        }

        if(groundCheck.OnTriggerEnter2D(Collider2D Floor) == true){
            jumpNumberT = jumpNumber;
        }
       
    }
}
1 Answers

Take a look at the numbers found within the error message:

Assets\Scripts\CharacterMovementController.cs(31,52): error CS1003: Syntax error, ',' expected

The (31,52) is providing the line number and the character number (respectively) where the error is occurring.

In this case, there is a syntax error in the call to method OnTriggerEnter2D. Depending on the intent, you may need to pass Floor or Collider2D.Floor as the argument.

Related