What Identifier should I be using?

I am using a tutorial on a stamina bar however it says ‘movement’ is the wrong identifier. It works for the person in the tutorial however they are using an older patch.

var curStam : float = 100.0;
var maxStam : float = 100.0;
 
var isSprinting : boolean = false;
 
var StaminaBar : Texture2D;
 
var staminaBarLength : float;
var percentOfStamina : float;
 
var stamCooldown : boolean = false;
 
 
function OnGUI () {
 
GUI.DrawTexture(Rect((Screen.width/2) - 100, 10, staminaBarLength, 10), StaminaBar);
 
}
 
 
function Update () {
 
 
percentOfStamina = curStam/maxStam;
staminaBarLength = percentOfStamina*100;
 
 
        if(Input.GetKey("left shift") && curStam > 0 && stamCooldown == false ) {
                        movement.maxForwardSpeed = 20.0;
                        isSprinting = true;
                       
                Debug.Log(movement.maxForwardSpeed);
}
 
        else {
                movement.maxForwardSpeed = 10.0;
                isSprinting = false;
               
                Debug.Log(movement.maxForwardSpeed);
       
        }
        if(isSprinting == true && curStam >= 0) {
       
        curStam--;
       
}
        if(isSprinting == false && curStam < 100.0) {
 
        curStam++;
 
}
        if(curStam == 0) {
       
        stamCooldown = true;
       
        }
       
        if(curStam == 100.0) {
       
        stamCooldown = false;
       
       
        }
}

Where does the variable/object 'movement' come from? It's not declared anywhere in the UnityScript you posted.

It would also help if you provided a link to the tutorial you were following, so we can see the context of your script.

1 Answer

1

Are you using the character motor script? This script from the tutorial is trying to access a CharacterMotorMovement class instance called movement that you don’t have.

Wherever

movement.maxForwardSpeed

Is written, either change it to alter the movement speed in your script or remove those lines entirely, as they aren’t necessary for any of the calculations.