I wonder if any of you could help. I have been using this script for my first person controller footstep sound, and it works great. However, I would ideally like it so that when I press the vertical up key on my keyboard ONCE, it would equate to ONE footstep. Right now, I have to press the vertical “up” key for a couple seconds for the footsteps to begin in a continuous motion.
Here is my script, for clarity:
function Update()
{
if(Input.GetButtonDown("Vertical"))
{
audio.Play ();
}
if (Input.GetButtonUp("Vertical"))
{
audio.Pause();
}
}
Animation events are really handy for this sort of thing. Each time your character’s animation puts their foot on the ground, the animation can call a function (say, “OnFootDown”), which can play a sound, emit some particles, or do whatever else you need.
Animation events only work with the legacy animation system, so if you are using Mecanim, it won’t work. The only audio pause function I can find is the one connected to audiolistener. Perhaps have a good look at the audio functions and find what you are looking for, unless you are using the legacy animation system.
Set it to play once. It’s going to be small, so you could probably just name a clip and set that one to play once and another to loop. Otherwise you could do it through code, also, or you could use stop I think, which will cause it to start over when you use play the next time, or use a coroutine and stop it after so much time. I have my loop timed to the walk cycle, so there’s no way I would mess with it. I would use audacity to make another one that started with no pause and have it play once.