Decreasing footstep length when key pressed

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);

        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 {

function Awake(){

If you guys have a great way to solve my question, please post them below! I would appreciate it :slight_smile:



You will need to change the audioStepLength from your sprint script.

To start of, you will need a reference to your footsteps script.

You do that by using GetComponent 1

Then you need to change audioStepLength to a lower number when running and back to 0.3 when walking.