- Home /
 
Scripted Animation Not Playing
I have created animation by using script. I want to create an animation of camera between texts which are generated at random locations. This is my script.
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic ;
 [RequireComponent (typeof(GenerateTexts))]
 [RequireComponent(typeof(Animation) ) ]
 public class CameraAnimation : MonoBehaviour {
     private List<GameObject> texts;
     private List<TextMesh> textMeshes;
     public bool done=false;
     void Update(){
         if (done == false) {
             textMeshes = new List<TextMesh> ();
             texts = this.gameObject.GetComponent<GenerateTexts> ().generatedTexts;
             foreach (GameObject o in texts) {
                 textMeshes.Add ( o.GetComponent <TextMesh>());
             }
             AnimationCurve curvex = new AnimationCurve();
             AnimationCurve curvey = new AnimationCurve();
             AnimationCurve curvez = new AnimationCurve();
             for ( int i = 0 ; i < texts.Count;i++){
                 curvex.AddKey (new Keyframe(i*2,texts[i].transform.localPosition.x));
                 curvey.AddKey (new Keyframe(i*2,texts[i].transform.localPosition.y));
                 curvez.AddKey (new Keyframe(i*2,texts[i].transform.localPosition.z));
             }
             AnimationClip clip = new AnimationClip();
             clip.SetCurve("", typeof(Transform), "localPosition.x", curvex);
             clip.SetCurve("", typeof(Transform), "localPosition.y", curvey);
             clip.SetCurve("", typeof(Transform), "localPosition.z", curvez);
             this.GetComponent<Animation>().AddClip(clip, "anim");
             this.GetComponent<Animation>().Play("anim");
             done = true ;
             Debug.Log ("executed");
         }
     }
 }
 
 
               Please tell me why animation is not running? Please I am waiting for trillion of micro seconds. No answer?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by ZDS Alpha · Apr 07, 2014 at 06:11 AM
Thanks for not posting anything.
The problem is solved!
Hi, i've the same problem. Can you post and explain solution? thanks
Your answer