- Home /
Animation event triggering step on frame
I've added 2 events to the walk animation of the built in 3rd person controller asset to do some testing. I've added the following code to see if I can send events to trigger step sounds. The timing seems to be working fine, but there are some residual triggers happening as the character comes to a rest. I thought maybe there should be a condition to make sure the keyboard input is active as well, but then there is some velocity deceleration on the character. Does anybody have any advice or solutions for this ?
using UnityEngine; using System.Collections;
public class AudioFrameTrigger : MonoBehaviour {
public AudioClip a1;
public AudioClip a2;
AudioSource audio;
// Use this for initialization
void Start () {
audio = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
}
public void PrintFloat (float theValue) {
Debug.Log ("PrintFloat is called with a value of " + theValue);
if (theValue == 0.1f)
{
audio.PlayOneShot (a1);
}
if (theValue == 0.2f)
{
audio.PlayOneShot (a2);
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I run a script when a button is highlighted 3 Answers
Need help with attacking animation!! 1 Answer