using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// This class allows an audio clip to be played during an animation state.
///
public class PlayAudioClip : StateMachineBehaviour
{
///
/// The point in normalized time where the clip should play.
///
public float t = 0.5f;
///
/// If greater than zero, the normalized time will be (normalizedTime % modulus).
/// This is used to repeat the audio clip when the animation state loops.
///
public float modulus = 0f;
///
/// The audio clip to be played.
///
public AudioClip clip;
float last_t = -1f;
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
var nt = stateInfo.normalizedTime;
if (modulus > 0f) nt %= modulus;
if (nt >= t && last_t < t)
AudioSource.PlayClipAtPoint(clip, animator.transform.position);
last_t = nt;
}
}