Hey all, I’m super super new to unity and am trying to figure out a way to trigger a sound whenever the character I’ve made (rigged and animated) goes into a certain pose.
The animations consist of basic punching movements, how would I go about this? would I have to create a box collider and whenever the fists of my character pass through the box it would trigger a sound? If thats even possible, how do I do this lol? I wanna do the same thing for a material swap on my character itself (facial expressions changing). Any help is appreciated,Hey all I’m super super new to Unity (doing this for a Uni Project),
I have a character that I’ve rigged in Maya and a basic punching animation has been added to it in unity. How do I trigger a sound to play every time the character goes into a certain pose? Do I have a collision box hovering where the hand goes and then try to trigger animation from there? I’m not even sure how to do this. Any help would be appreciated, thanks.
When you have the animation play start a coroutine and time when the sound effect needs to happen and use PlayOneShot
I think the easiest way to do this is by using Animation Events. First, create a script to handle the audio and attach it to your character:
public class AudioManager : MonoBehaviour
public AudioSource audioSource;
public AudioClip punchSound;
public void PlayPunchSound()
audioSource.clip = punchSound;
Now you need to call the “PlayPunchSound()” through an AnimationEvent. Click on your character asset, go to the Animation tab and choose the animation clip that you want to add the event, it will look something like this:
Scroll down to find the “Events” foldout, and click on it. Now find the frame of the animation that you want the audio clip to play and press the Add Event button. Write the name of the method that plays the sound in the “Function” space, it should look like this:
Now whenever that animation plays, it will play the audio clip as well. Make sure that your character has the AudioManager script and an AudioSource.