I’ve got an animation event in a running animation to provide footsteps, but I can’t get any audio out of it. Here’s my script
using UnityEngine;
using System.Collections;
public class FootstepAudio : MonoBehaviour {
public AudioClip[] footsteps;
public Animator anim;
AnimationEvent footstepsEvent;
public void PlayFootsteps (){
audio.clip = footsteps[Random.Range(0, footsteps.Length)];
if(!audio.isPlaying){
Debug.Log ("Audio isn't playing");
audio.Play ();
}
if (audio.isPlaying) {
Debug.Log ("Audio IS playing");
}
print (audio.clip.name);
}
}
I know PlayFootsteps() is running because it outputs the name of the audio clip and it tells me whether or not audio.isPlaying returns true. The thing is… it does return true much of the time, however I don’t hear sound playing. Sometimes I do hear the sound trying to play, but only a fraction of a second is played.
I’ve also tried putting a sound on my jump pads that does not include an animation event and it won’t work, either. I don’t have any other sound playing anywhere else in my scene and I have an audio listener on my camera. Anyone have any suggestions for what might be going on here?