Hi everyone, I’ve being working on a horror game and I’ve found a “Footstep” script witch creates sounds when I’m walking (W,D,S,A Keys) and I’ve managed to create a Sprint function when pressing the Shift button but there’s one thing that doesn’t really match together: When I sprint with my Footstep Script, my footstep length remains the same. What I’m saying is when I press the Shift key, I want my sound length to be decreased witch means, increasing my speed of the footstep sound.
So here’s my script of the Footstep function:
var audioStepLength = 0.3;
var footAudio : AudioClip[];
function OnTriggerEnter (other : Collider) {
var chao : System.Net.Sockets.SendPacketsElement = other.GetComponent(System.Net.Sockets.SendPacketsElement);
if(chao){
footAudio = chao.footsteps;
}
}
function PlayStepSounds () {
var controller : CharacterController = GetComponent(CharacterController);
while (true) {
if (controller.isGrounded && controller.velocity.magnitude > 0.3) {
var volume = Mathf.Clamp01(Time.time);
audio.PlayOneShot(footAudio[Random.Range(0, footAudio.Length)], volume);
yield WaitForSeconds(audioStepLength);
} else {
yield;
}
}
}
function Awake(){
PlayStepSounds();
}
If you guys have a great way to solve my question, please post them below! I would appreciate it
Thanks!
~crusherxman