Resolved Invalid expression term ')'

Xade

New member
Joined
Dec 21, 2020
Messages
3
Programming Experience
Beginner
C#:
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody rb;

    public float forwardForce = 2000f;

    // FixedUpdate weil Physik und so
    void FixedUpdate ()
    {
        // Add a forward force
         rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if ( Input.Getkey("d"))
        {
            rb.AddForce(500 * Time.deltaTime, 0, 0,);
        }
    }
}

wheres the problem the console says Assets\PlayerMovement.cs(17,52): error CS1525: Invalid expression term ')'
 
Last edited by a moderator:
Solution
Unless that AddForce method has an optional fourth parameter, that code is invalid.
Actually, I was thinking about how you treat optional parameters in VB. In C#, that's invalid even if there is an optional parameter. If there is an optional parameter and you don't know how to deal with it, that's what you should research. I suspect that you just need to remove a spurious comma though.

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,813
Location
Sydney, Australia
Programming Experience
10+
On line 17 of the code, which is now easily identifiable since I formatted it, you have a comma followed by a closing parenthesis. Unless that AddForce method has an optional fourth parameter, that code is invalid. Remove the comma if there should only be three arguments or else add the missing fourth argument.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,813
Location
Sydney, Australia
Programming Experience
10+
Unless that AddForce method has an optional fourth parameter, that code is invalid.
Actually, I was thinking about how you treat optional parameters in VB. In C#, that's invalid even if there is an optional parameter. If there is an optional parameter and you don't know how to deal with it, that's what you should research. I suspect that you just need to remove a spurious comma though.
 
Solution

Xade

New member
Joined
Dec 21, 2020
Messages
3
Programming Experience
Beginner
Actually, I was thinking about how you treat optional parameters in VB. In C#, that's invalid even if there is an optional parameter. If there is an optional parameter and you don't know how to deal with it, that's what you should research. I suspect that you just need to remove a spurious comma though.
Thank you so much i really didnt saw that.
 
Top Bottom