I am trying make a footstep sounds when i walk in my First Person Controller. I also would like the footsteps to go faster when i sprint and slower when i crouch. Please help. I’m no coder
Did you try this? :
Footsteps Sounds - Questions & Answers - Unity Discussions ?
public AudioClip walkAudio;
public float audioTimer;
void Update() {
/* This basically asks, "is the timer greater than zero?". If the statement returns true, the timer will begin to decrease in time. You need this to hold a pattern between steps. If you use 'audio.PlayOneShot()' alone, it won't sound right.*/
if (audioTimer > 0)
audioTimer -= Time.deltaTime;
/* This is asking, "is the timer less than or equal to zero (when subtracting by time, Unity will almost never land directly on zero), and is the vertical or horizontal axis greater than zero (these are measured in floats, numbers with a decimal). They must be put in brackets as you'll have issues with an 'and' and 'or' statement together. If all are returned true, the sound will play and the timer will be set to the length of the AudioClip*/
if (audioTimer <= 0 && (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0))
{
audio.PlayOneShot(walkAudio);
audioTimer = walkAudio.length;
}
/* Now, to change the gap between steps, you change the value of the timer. Ex: sprinting - audioTimer = walkAudio.length * 2;*/
}
If you have any questions, feel free to ask.