- Home /
Problem With Walking Sounds
When i use this code footsteps gets bugy when you press W and D at the same time walking sounds not playing sometimes.
#pragma strict
var Walk : AudioClip;
function Update()
{
if (Input.GetKeyUp (KeyCode.W))
{
audio.clip = Walk;
audio.Stop();
}
if (Input.GetKeyDown (KeyCode.W))
{
audio.clip = Walk;
audio.Play();
}
if (Input.GetKeyUp (KeyCode.D))
{
audio.clip = Walk;
audio.Stop();
}
if (Input.GetKeyDown (KeyCode.D))
{
audio.clip = Walk;
audio.Play();
}
if (Input.GetKeyUp (KeyCode.A))
{
audio.clip = Walk;
audio.Stop();
}
if (Input.GetKeyDown (KeyCode.A))
{
audio.clip = Walk;
audio.Play();
}
if (Input.GetKeyUp (KeyCode.S))
{
audio.clip = Walk;
audio.Stop();
}
if (Input.GetKeyDown (KeyCode.S))
{
audio.clip = Walk;
audio.Play();
}
}
Comment
Answer by DaveA · Feb 07, 2014 at 09:25 AM
Get this asset, it takes care of everything for you: Advanced Footstep System
Your answer
Follow this Question
Related Questions
How to add sound to when a key is pressed 1 Answer
play car engine sound only when W key is pressed down? 0 Answers
Play Looped Sound? 4 Answers
Play sound by pressing button 2 Answers