Hi,
i have a Gameobject with animator component with a single animation and i want to restart the animation from the beginning when i press i key but i don’t know ho to do it.
This is my actual code:
using UnityEngine;
using System.Collections;
public class CamAnimController : MonoBehaviour {
public static CamAnimController ins;
void Awake(){
ins = this;
}
void Start () {
stopAnim();
}
void Update(){
if(Input.GetKey(KeyCode.UpArrow)){
startAnim();
}
if(Input.GetKey(KeyCode.DownArrow)){
stopAnim();
}
}
void stopAnim(){
gameObject.GetComponent<Animator>().StopPlayback();
gameObject.GetComponent<Animator>().enabled = false;
}
void startAnim(){
gameObject.GetComponent<Animator>().enabled = true;
gameObject.GetComponent<Animator>().SetBool ("isRestarting", true);
gameObject.GetComponent<Animator>().Play("C4D Animation Take");
}
}
with this when i press arrow up the animation start and when i press arrow down the animation pause but when i press the arrwo up i need that the animation restart from the beginning, somebody can help me?
Thanks in advance!