- Home /
Play sound effect throughtout an entire animation clip
Hey everyone,
I was trying to play a sound effect over an entire animation but I wasn't sure how to do it. For short sound effects, I usually use events in the animation window to call a function like this. void FootSteps() { GetComponent().PlayOneShot(footSound); }
This works perfectly for something like footsteps, but how can I play a sound effect for something like a rocket launch animation or flying plane. (The Sound effect would play from the start to end of the animation clip).
Thanks
Answer by Magso · Apr 04, 2019 at 10:12 PM
You can turn audioSource's mute on and off in the animation. Make sure loop is checked and animate the volume and pitch to polish it.
Oh, to make sure the SFX is playing throughout the whole animation. I was thinking of adding 2 events, one at the start of the animation calling a function StartSound and the 2nd event calling StopSound. These 2 functions might look something like this.
public void StartSound()
{
GetComponent<AudioSource>().Play();
}
public void StopSound()
{
GetComponent<AudioSource>().Stop();
}
Not sure if this works or if its ideal for something like a rocket launch or flying plane SFX. Or did you mean I should just Start the event and make sure the audioSource's loop is checked? That way the SFX won't get interrupted in a looping animation right?
That script method would be the best solution and should work, just ensure you set the sound as looping. The first suggestion of setting it to mute and unmute through the animation would achieve the same effect however the audio source will still be playing and using system resources.
Using events shouldn't be a problem, you can start and stop the sound however you want as long as loop is checked. The audio has nothing to do with the animation because you can only animate properties on the audiosource, and the audiosource manages the audio. Nothing's interrupted by an animation loop.
Ok perfect thank you guys so much @Uni010 @stuartmcroberts
Your answer
Follow this Question
Related Questions
Multiple gapless sound loops from one AudioSource (C#) 2 Answers
Looping an audio while holding "shift key" 1 Answer
Loop audio with Bolt 1 Answer
Can I make animations snap to a frame? 1 Answer
Audio not playing when OnTriggerEnter2D 2 Answers