- Home /
Question by
tengfeng · Apr 20, 2016 at 10:34 AM ·
animationanimatortriggertimer-script
i need the animation to be trigger on a specific time but it is not trigger, script got no error. Not sure where is the problem, need help please.
using UnityEngine; using System.Collections;
public class ClockBaseAnimation : MonoBehaviour {
[SerializeField] private float currentAmount;
[SerializeField] private float speed;
private float timer;
Animator anim;
// Use this for initialization
void Start () {
currentAmount = 60;
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
currentAmount -= speed * Time.deltaTime;
if (currentAmount <= 55 && currentAmount >= 0) {
anim.SetTrigger ("TimerBase");
}
else {
anim.SetTrigger ("idle");
}
}
}
Comment
Answer by aditya · Apr 20, 2016 at 10:38 AM
you are setting the trigger in Update, this means you are triggering too fast that your animation is not playing even its first frame
Hi aditya, i am new to progra$$anonymous$$g, not sure what you mean by triggering to fast. So does that mean that i should not use anim.SetTrigger ("TimerBase"); and set it to GetComponent().Play ("TimerBase");
or should i remove the void Update?