Hi,
I made a script in Javscript for random footstep sounds.
But it's working half.
I have a float for the delay between the sounds for the normal walk speed and idem dito for sprinting.
The nextFoot float does switch from the 0.525(walkspeed) to 0.3(sprintspeed) but the delay doesn't change.
If I manually change the nextFoot float in the inspector, the delay does get shorter or longer, but it doesn't work when I press Left shift.
Anyone know how I can fix this?
private var isWalking : boolean = false;
private var isGrounded : boolean = false;
private var controller : CharacterController;
var nextFoot : float;
var nextFootDefault = 0.525;
var nextFootSprint : float;
var Steps : AudioClip[];
function Awake(){
controller = GetComponent(CharacterController);
}
function Update(){
if(controller.velocity.sqrMagnitude > 0.15 ){
isWalking = true;
}
else {
isWalking = false;
}
if (Input.GetKeyDown("left shift")){
nextFoot = nextFootSprint;
}
else if (Input.GetKeyUp("left shift")){
nextFoot = nextFootDefault;
}
}
InvokeRepeating("Walking", 0, nextFoot);
function Walking(){
if((isWalking) && (controller.isGrounded)){
audio.PlayOneShot(Steps[Random.Range(0,Steps.length)]);
}
}
↧