What does "error CS1003: Syntax error, ',' expected" mean?

creampuff1

Member
Joined
Aug 22, 2023
Messages
6
Programming Experience
Beginner
I keep getting this error and I have no idea how to fix it
here is my code if that helps
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeMovement : MonoBehaviour
{
    public float moveSpeed == 5;
    // Start is called before the first frame update
    void Start()
    {
       
    }
    // Update is called once per frame
    void Update()
    {
       transform.position = transform.position + (Vector3.Left * moveSpeed);
    }
}
 
Last edited by a moderator:
Did you really mean to put == on line 6? Shouldn't that be =?
 
For future reference, you need to provide ALL the relevant information in your post. Write the post first, then summarise it in the title. Don't include the crux of the issue in the title only.
 
As for the issue, the error message is a bit misleading but that's because the compiler is making a best guess at what you were trying to do and telling you how to fix that. It assumed that you meant to perform an equality comparison and your mistake was what came after that. If you fix the code to perform an assignment then what comes after will be correct so that error will be cleared. Despite the error message not addressing the actual issue, it would have told you what line the issue was on and there's not much code on that line, so it shouldn't have been too hard for you to ask yourself what it was that you wanted to do and whether the code you had actually did it, knowing that something was wrong. We've all mixed up = and == one way or another at various times but it's always something to check if you get a cryptic error message.
 
My gut feel from the two threads that the OP has created so far, is that they are trying to climb two steep learning curves at the same time: learning the C# language, and learning how to use Unity. This makes things four times as hard.
 
Well, there is a minor small syntax error which you can fix it by replacing your code with below one.

C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PipeMovement : MonoBehaviour
{
    public float moveSpeed = 5; // Use a single equals sign for assignment.

    // Update is called once per frame
    void Update()
    {
        // Move the pipe to the left.
        transform.position += Vector3.left * moveSpeed * Time.deltaTime;
    }
}

Thanks
 

Latest posts

Back
Top Bottom