Sound Problem?

Hello Guys,

I am having a lot of trouble getting a sound to play while the FPS controller is walking using 4.6.1f. Yes, I know I should really be using Unity5 but I don’t want to mix the packages.

Anyway, the sound I am getting is close to electrical static than a foot step sound. I can sort of understand why it might be happening with the sound being generated within an update, but, I cannot figure out how to stop it occurring.

As always a big thankyou goes out to those who can help with this problem.

Regards,
CK.

The code I have used is as follows:

#pragma strict

var controller: CharacterController;

function Start () {
     controller = GetComponent(CharacterController);
     }

//playerwalking function
function Update () {
     //print("isGrounded:"+controller.isGrounded+"Velocity:"+controller.velocity.magnitude);

    if (controller.isGrounded && (controller.velocity.magnitude > 1 && controller.velocity.magnitude < 11) ) {
    print("walkies........");
    audio.Play();
    }
else{
     print("notwalkies...");
     audio.Stop();
     }

}//end function

Same problem as here

1 Like

Aha - so I was right about the sound firing every frame. So, I tried the solution at that link using the:

if NOT audio.isPlaying then audio.Play

and that stopped the weird electrical static. I was surprised that Unity sort of recommended the way I was using in it’s Scripting API docs with the results that a person is going to get - oh well. The only problem now with the sound is with the timing, I think I’ll enlarge the sound file to make it longer rather than try and code a solution - I’m too much of a noob for that :p.

Thanks greatly for your post it really helped :sunglasses:.