void create_animation() { AnimationCurve curve_height, curve_x, curve_z; AnimationClip clip; Animation anim; tempcount = 4; time_slice[] height_data = new time_slice[144]; for (int time = 0; time < 143; time++) { height_data[time] = new time_slice(); for (int i = 0; i < 20 * 20; i++) { height_data[time].height[i] = float.Parse(strArr[tempcount - 2]); height_data[time].x[i] = float.Parse(strArr[tempcount - 3]); height_data[time].z[i] = float.Parse(strArr[tempcount - 1]); tempcount = tempcount + 4; } } Debug.Log(height_data.Length); tempcount = 0; for (float i = 0; i < 20; i++) { for (float j = -0; j < 20; j++) { ammo = GameObject.Find(i.ToString() + "," + j.ToString() + "terrain"); anim = ammo.gameObject.GetComponent <Animation>(); curve_height = new AnimationCurve(); curve_x = new AnimationCurve(); curve_z = new AnimationCurve(); clip = new AnimationClip(); for (int k = 0; k < 143; k++) { curve_height.AddKey(k * timesclice, height_data[k].height[tempcount]); curve_x.AddKey(k * timesclice, height_data[k].x[tempcount]); curve_z.AddKey(k * timesclice, height_data[k].z[tempcount]); } tempcount++; clip.legacy = true; clip.SetCurve("", typeof(Transform), "localPosition.y", curve_height); clip.SetCurve("", typeof(Transform), "localPosition.x", curve_x); clip.SetCurve("", typeof(Transform), "localPosition.z", curve_z); anim.AddClip(clip, "anim"); anim.Play("anim"); //Debug.Log(clip.length); anim["anim"].speed = 1; } } }
void create_animation() { AnimationCurve curve_height,curve_x,curve_z; AnimationClip clip; Animation anim; tempcount = 4; time_slice[] height_data = new time_slice[144]; for (int time=0; time<143; time++) { height_data[time] = new time_slice(); for(int i=0;i<20*20;i++){ height_data[time].height[i] = float.Parse(strArr[tempcount-2]); height_data[time].x[i] = float.Parse(strArr[tempcount-3]); height_data[time].z[i] = float.Parse(strArr[tempcount-1]); tempcount = tempcount+4; } } Debug.Log (height_data.Length); tempcount = 0; for (float i=0; i<20; i++) { for (float j=-0; j<20; j++) { ammo = GameObject.Find (i.ToString () + "," + j.ToString () + "terrain"); anim = ammo.gameObject.GetComponent<Animation>(); curve_height = new AnimationCurve(); curve_x = new AnimationCurve(); curve_z = new AnimationCurve(); clip = new AnimationClip(); for(int k=0;k<143;k++){ curve_height.AddKey(k*timesclice,height_data[k].height[tempcount]); curve_x.AddKey(k*timesclice,height_data[k].x[tempcount]); curve_z.AddKey(k*timesclice,height_data[k].z[tempcount]); } tempcount++; clip.legacy = true; clip.SetCurve("",typeof(Transform), "localPosition.y", curve_height); clip.SetCurve("",typeof(Transform),"localPosition.x",curve_x); clip.SetCurve("",typeof(Transform), "localPosition.z", curve_z); anim.AddClip(clip,"anim"); anim.Play("anim"); //Debug.Log(clip.length); anim["anim"].speed =1; } } }