- Home /
How to synchronize sound and animation loop?
I have animations that will loop and sounds that will go along with those animations. However, the sounds are usually shorter than the animations themselves. For example I have an animation "laugh" which lasts 5 seconds, while the respective sound for it lasts only 3 seconds. I need to make it so the laugh sound plays when the animation starts as well as when it loops and starts again. What is the best way to have the sounds synchronized? I could call an InvokeRepeat function for the duration of the animation, but then I would have to deal with canceling invokes when he animation is interrupted and I am trying to avoid it. I am hoping there is a cleaner, more elegant solution. Any ideas?
Thanks in advance!
Answer by komodor · May 27, 2015 at 10:29 AM
use animation events to start and stop playing the sound ... dannyskim is right but it's not always best solution if you use animation for something else then animation itself (state machine in mecanim for example), also you might need sound longer then animation overlaping over other animations, you might need sound effects etc.
Answer by dannyskim · May 21, 2012 at 10:36 PM
No offense, but you're thinking about it the wrong way. The best way for a sound to match up with an animation is to edit the sound to match the animation, not try to programmatically control it.
There's a slew of different audio suites that allow you to import a movie file and time your sound clip frame by frame.
Your answer
Follow this Question
Related Questions
Reading datas from sound files 2 Answers
Creating a realtime cinema sequence in Unity. 2 Answers
Playing sound when animation starts 1 Answer
Loop Animation In Script? 2 Answers
How should I sync animations? 1 Answer