GetComponent doesn't work, "expected ')'" and "is a method but not valid for current context"

PlayerMotor.GetComponent.(<CharacterMotor>)().MaxForwardSpeed *= SpeedMultiplier;

Why doesn’t this script work? I got straightforward error. I placed 1st person FPS controller. Now I want to increase it by SpeedMultiplier, but both GetComponent and get highlighted, any idea how this come?

GetComponent syntax for C# is GetComponent().

2 Likes
PlayerMotor.GetComponent<CharacterMotor>().MaxForwardSpeed *= SpeedMultiplier;

Doesn’t work, did I mistake some? It’s not even about working, it’s about editor already prompting an error.

Copy and paste the error for us.

Error 1 ‘CharacterMotor’ does not contain a definition for ‘MaxForwardSpeed’ and no extension method ‘MaxForwardSpeed’ accepting a first argument of type ‘CharacterMotor’ could be found (are you missing a using directive or an assembly reference?) C:\Users------\Documents\shot and hit\Assets\Scripts\Triggers and Initializers\Handicaps\user_receive.cs 23 52 Assembly-CSharp-vs

With that error then we need to look at the CharacterMotor class and where does it define MaxForwardSpeed? Did you capitalize it wrong, like is it maxForwardSpeed or Maxforwardspeed or something?

Like what rrh said, in your snippet you are using the wrong variable name:

PlayerMotor.GetComponent<CharacterMotor>().maxForwardSpeed *= SpeedMultiplier;