- Home /
Triggering sounds on collision?,Rigged Character animation collision
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.
Answer by Magso · May 19, 2019 at 11:37 PM
When you have the animation play start a coroutine and time when the sound effect needs to happen and use PlayOneShot
Answer by Kim-Nobre · May 21, 2019 at 10:01 PM
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:
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public AudioSource audioSource;
public AudioClip punchSound;
public void PlayPunchSound()
{
audioSource.clip = punchSound;
audioSource.Play();
}
}
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.
Your answer
Follow this Question
Related Questions
Check for collision while animating 0 Answers
Gameobject not detecting collison from other Box Collider 2D [SOLVED?] 2 Answers
BoxCollider get stuck when dragging over the border of two BoxColliders 1 Answer
get only one colliding body 3 Answers
Why the npc character walking strange when using a Rigidbody and Is Kinematic on enabled ? 1 Answer