I have a singular footstep sound. I want it to sound random every time, so it doesn’t get old when you walk a bunch. The game is very high paced, so I want it to play over and over, and if it’s already playing, play it again, but don’t stop the current sound.
This is my current code, which checks the velocity of the character controller and checks if you aren’t jumping:
// Controller = The character controller
// isGrounded = A bool, true if you are touching the ground, false if not
// groundSound = An AudioSource
if (isGrounded && controller.velocity.x != 0)
{
groundSound.pitch = Random.Range(0.85f, 1.15f);
groundSound.Play();
}
It works, but only when you stop walking, because it keeps playing over and over again, stopping the previous sound. I want to have a small delay between each play, and if possible, play it over the previous sound.
Any idea on how I could do this? I am a bit new to unity.