Animation does not happen on exact timed event.
I am having a problem where my animation will not play at a exact time I was using
using UnityEngine; using System.Collections;
public class audio_timed_animation : MonoBehaviour {
float timeLeft = 0.0f;
public float eventtime;
// Use this for initialization
void Start () {
GetComponent<AudioSource>().Play();
}
// Update is called once per frame
void Update () {
timeLeft += Time.deltaTime;
if (eventtime == timeLeft);
{
GetComponent<AudioSource>().Play();
GetComponent<Animation>().Play("dooropen");
}
}
}
But when I am using == the sound will play but the animation will not. If I use the <= or >= the animation will play repeatedly before and after the time but does nothing with == I am at a bit of a loss and any thoughts would be greatly appreciated.
I found out how to get around it.
currenttime += Time.deltaTime;
if (currenttime >= eventtime)
{
if (currenttime <= eventtime + .1)
{
audio.PlayOneShot(open, 0.5F);
GetComponent<Animation>().Play("open");
}
}
I do not really think I should have to do it this way and I do not know why == does not work on animations but at least it is working.
Your answer
Follow this Question
Related Questions
how to change between animations with pressing buttons 0 Answers
Im using the HQ Fighting Animation FREE pack and have a problem with the end of the animations 0 Answers
How Play 2 animations use AddMixingTransform . 0 Answers
OnTriggerEnter triggers many times per trigger. 0 Answers
I am a basic learner can anyone help me to design a game...? 0 Answers