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*.transform.localPosition.x));*
_ curvey.AddKey (new Keyframe(i2,texts.transform.localPosition.y));_
_ curvez.AddKey (new Keyframe(i2,texts*.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().AddClip(clip, “anim”);
this.GetComponent().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?