- Home /
Footsteps Problem
Hello , i want to add footsteps sound to player
public float walkSpeed = 6.0f;
public float runSpeed = 10.0f;
public AudioClip[] dirt ;
void Update () {
if (!grounded && walkSpeed > 4) {
audio.clip = dirt[Random.Range(0, dirt.Length)];
audio.Play();
}
but sound only playing when i jump it's not playing while im moving any help would be great.
! is not, and I'm sure you mean walkSpeed < 4, but you might also want to try adding a current speed value.
Answer by InvincibleCat · Feb 04, 2015 at 08:19 PM
Ok... So Add this to your variables:
public float SoundFrequency = 1.0f;
Add this on Start:
StartCoroutine(PlaySound());
Then remove your condition and the code from your Update Method.
And change the PlaySound method to:
private IEnumerator PlaySound()
{
while (true)
{
if (grounded && speed > 4)
{
audio.clip = dirt[Random.Range(0, dirt.Length)];
audio.Play();
yield return new WaitForSeconds(SoundFrequency);
}
else
{
yield return null;
}
}
}
The only thing you need to change is that speed is NEVER < 4. So even when you are not moving the sounds are still played.
Your answer
Follow this Question
Related Questions
Improved Footsteps system 1 Answer
audio is distorted at speed 1 Answer
Sounds are shaky at high speed. 0 Answers
Decreasing footstep length when key pressed 1 Answer
Scripting Walking Sound Help? 1 Answer