using UnityEngine;
using System.Collections;
public class amimation : MonoBehaviour {
float speed;
AnimationClip aclip;
AnimationCurve acurvex;
AnimationCurve acurvey;
AnimationCurve acurvez;
Transform[] key;
// bool
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// zz_animation ();
// zz_animation2 ();
zz_animation3 ();
}
void zz_animation()
{
if (Input.GetKey (KeyCode.W))
{
this.animation.Play("runforward");
this.transform.Translate(Vector3.forward*Time.deltaTime);
this.animation["runforward"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.W))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.S))
{
this.animation.Play("runbackwards");
this.transform.Translate(-(Vector3.forward)*Time.deltaTime);
this.animation["runbackwards"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.S))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.A))
{
this.animation.Play("strafeleft");
this.transform.Translate((Vector3.left)*Time.deltaTime);
this.animation["strafeleft"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.A))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.D))
{
this.animation.Play("straferight");
this.transform.Translate(-(Vector3.left)*Time.deltaTime);
this.animation["straferight"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.D))
{
this.animation.Play("idle");
}
if (Input.GetKey (KeyCode.Space))
{
// this.animation.Play("jump");
// this.animation["jump"].speed=1.0f;
}
else if(Input.GetKey(KeyCode.Space))
{
this.animation.Play("idle");
}
}
void zz_animation2()
{
if(Input.GetKey(KeyCode.W))
{
this.animation.CrossFade ("runforward",1.5f);
this.transform.Translate (Vector3.forward *Time.deltaTime);
this.animation["runforward"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.W))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.S))
{
this.animation.CrossFade ("runbackwards",1.5f);
this.transform.Translate (-Vector3.forward *Time.deltaTime);
this.animation["runbackwards"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.S))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.A))
{
this.animation.CrossFade ("strafeleft",1.5f);
this.transform.Translate (Vector3.left *Time.deltaTime);
this.animation["strafeleft"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.A))
{
this.animation.Play("idle");
}
if(Input.GetKey(KeyCode.D))
{
this.animation.CrossFade ("straferight",1.5f);
this.transform.Translate (-(Vector3 .left ) *Time.deltaTime);
this.animation["straferight"].speed=1.0f;
}
else if(Input.GetKeyUp(KeyCode.D))
{
this.animation.Play("idle");
}
}
void zz_animation3()
{
acurvex = new AnimationCurve (new Keyframe(0,transform.localPosition.x),
new Keyframe(1,key[0].position.x),
new Keyframe(2,key[1].position.x),
new Keyframe(3,key[2].position.x),
new Keyframe(4,key[3].position.x),
new Keyframe(5,transform.localPosition.x));
acurvez =AnimationCurve.EaseInOut(0,transform.localPosition.z,key .Length +1,transform.localPosition.z);
for(int i=0;i<key.Length;i++)
{
acurvez.AddKey(i,key[i].position.z);
}
acurvey = AnimationCurve .Linear (0,transform .position.y,key.Length+1,transform.localPosition.y);
aclip.SetCurve ("",typeof(Transform),"localPosition",acurvex);
aclip.SetCurve ("",typeof(Transform),"localPosition",acurvey);
aclip.SetCurve ("",typeof(Transform),"localPosition",acurvez);
// animation.AddClip (clip:);
}
}
Animation曲线创建
最新推荐文章于 2024-05-26 13:31:34 发布