- Home /
Walking sound change
Hello!
I have this script for the walking sound, but it doesn't work. What's wrong?
#pragma strict
var WalkingSound : AudioClip;
function Update (){
if(Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
{
PlayerWalkSound();
}
}
function PlayerWalkSound(){
yield WaitForSeconds(1);
audio.volume = 0.5;
audio.clip = WalkingSound;
audio.pitch = Random.Range(0.8f, 1.0f);
audio.Play();
}
I must do it with yield instead of
if(!audio.isNotPlaying)
{
//stuff
}
because the time between the footstep sounds must be changeable cause of the different speeds. (sprint, crawl...)
I don't think the yiel thing replaces the !audio.isNotPlaying because from what i can see that the PlayerWalkSound will get called every frame when either horizontal or vertical is pressed. So after a second it would try to play the audio multiple times over the course of milliseconds.
I would suggest you orient your script on this one: http://answers.unity3d.com/questions/373508/footsteps-script-for-running-and-walking.html
Your answer
Follow this Question
Related Questions
Why does the audio sound different than the original ? 0 Answers
Sound wont play when triggered (javascript) 1 Answer
Unity audio solution 1 Answer
Stop audiosource clip from playing 1 Answer
Getting audio to play on collision 3 Answers