Animation Event Audio Clip not working!
I am using Animation Event to call a function that plays a simple sound. However, the sound is not playing absolutely.
I have tried everything, read tons of questions here, tutorials on google, Learning page on Unity - nothing! Actually everything looks correct and there are no errors in the console, it should work but it doesn't.
Here is the code of my script:
using UnityEngine;
using UnityEngine.Audio;
using System.Collections;
public class StepSounds : MonoBehaviour
{
public AudioClip stepSound;
private AudioSource source;
// Use this for initialization
void Start ()
{
source = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update ()
{
}
void StepAudio ()
{
source.PlayOneShot (stepSound);
}
}
I attach this script to an "EmptyChildGameObject" attached to each foot of my Model. Than I drag and drop the audio clip in the inspector correctly. If I set it to play on Awake it does. But when I go to my animation and i set the event to call the "StepAudio" function nothing happens.
I have tried many other methods but nothing works. I tried with colliders on each foot and a collider on the ground. It didn't work. I also set this collider as trigger and adapted the script for the OnTriggerEnter and etc.
Nothing works, the sound doesn't play.
The only thing that bothers me is that the animation where I set the events is part of a Blend Tree and the events are only set on the Walk_Forward animation - I was thinking because of the blending it wont call the Events correctly, but walking only forward should do it, and it doesn't !!
Please help me, your help will be very appreciated!
I am using Unity 5 and actually the rest of my project is pretty complicated for this to stop the development process!
Answer by HonoraryBob · Aug 30, 2016 at 10:09 PM
The script should be attached to the character's main GO, not to each foot. This works for me, although it doesn't exactly work flawlessly.