FPS Dynamic Speed variables

hi. im trying to make it so that my Fps can set his speed stat and that he will move faster with a higher number. I took the Fps that comes with unity and i tryed editing it, but it wont work. Help?

Yes i made sure that Spd in the Stats script is static.

Here’s what i changed in the code

class CharacterMotorMovement {

// The maximum horizontal speed when moving
var Spd : float = Stats.Spd;
var maxForwardSpeed : float = Spd;
var maxSidewaysSpeed : float = Spd;
var maxBackwardsSpeed : float = Spd*.3;

// Curve for multiplying speed based on slope (negative = downwards)
var slopeSpeedMultiplier : AnimationCurve = AnimationCurve(Keyframe(-90, 1), Keyframe(0, 1), Keyframe(90, 0));

// How fast does the character change speeds?  Higher is faster.
var maxGroundAcceleration : float = 30.0;
var maxAirAcceleration : float = 20.0;

// The gravity for the character
var gravity : float = 10.0;
var maxFallSpeed : float = 20.0;

// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
// Very handy for organization!

// The last collision flags returned from controller.Move
var collisionFlags : CollisionFlags; 

// We will keep track of the character's current velocity,
var velocity : Vector3;

// This keeps track of our current velocity while we're not grounded
var frameVelocity : Vector3 = Vector3.zero;

var hitPoint : Vector3 = Vector3.zero;

var lastHitPoint : Vector3 = Vector3(Mathf.Infinity, 0, 0);


Your problem is propably that you assigned the speeds only when the class get initialized. All your assignments after the variable declarations are done only once when the object is created. When you change Stats.Spd at runtime, Spd, maxForwardSpeed, maxSidewaysSpeed and maxBackwardsSpeed won’t change, why should they…

If you change Stats.Spd you need to update the other variables as well. There are several ways.

One would be to update them each frame like this:

// inside the UpdateFunction of the CharacterMotor.js
private function UpdateFunction () {
    movement.Spd = Stats.Spd;
    movement.maxForwardSpeed = movement.Spd;
    movement.maxSidewaysSpeed = movement.Spd;
    movement.maxBackwardsSpeed = movement.Spd * 0.3;
    // [...]

Or to update them only when you change your Stats.