I have been having a very hard time finding good information on starting and stoping animation via script via code and the animator.
I got my animation working thus far when a function is invoked but my one problem I am left with is the animation playing automatically when the scene starts.
Any ways heres the code if it helps.
// From Prefab
public class DestroyAtX : MonoBehaviour {
public float stopanim;
public float kill;
private Animator stoploganim;
public GameObject log;
// Use this for initialization
void Start () {
log = GameObject.Find("warn");
stoploganim = log.GetComponent<Animator>();
stoploganim.Play("GO");
}
// Update is called once per frame
void Update () {
if(transform.position.x < stopanim){
stoploganim.SetTrigger("STOP");
}
if(transform.position.x < kill){
DestroyObject(this.gameObject);
}
}
}
// From Plane with animation
public class WarnAnimTest : MonoBehaviour {
private Animator warnstop;
// Use this for initialization
void Start () {
warnstop = GetComponent<Animator>();
warnstop.StopPlayback();
}
// Update is called once per frame
void Update () {
}
}
That is what I did originally, I changed some code around since then, I'll try it again and let you know.
– aronatvw