-
Notifications
You must be signed in to change notification settings - Fork 53
8. Using JSAM with Mecanim
This guide assumes that you have set up AudioManager and have generated it's Audio Library already. If you'd like to bring yourself up to speed, you can read up on Getting Started with JSAM and Playing Your Sounds
Not only can you import animations into Unity, but you can also author them inside the Unity editor itself with it's robust animation system. This allows you to play multiple sounds at different times and different speeds in-engine rather than having to combine your sounds together into one file and syncing it up afterwards.
If you want to add sound to your animations, you can do so by using Animation events. To do so, you'll first want to select the GameObject
that holds your Animator
component and add the Audio Events
component to it.
The Audio Events
component holds a variety of useful functions that you can call during your animation's playback in order to play sounds. The main one would be PlaySoundByEnum
.
Navigate to the animation that you'd like to add a sound and scrub to the exact frame you'd like to play the sound. Once there, click on the button labelled Add Event
to add a new Animation Event
. The inspector should now give you the option of specifying a method to call from all the public methods attached to the Animator
's host GameObject
. Look for PlaySoundByEnum
.
You need only pass in the Enum name of your sound as a parameter to PlaySoundByEnum
. The next time your run the game, the sound will play when the animation plays that frame.
Note: When playing spatialized sounds this way, the listener will hear the sound as if it's playing from where the Animator is positioned.