Animation曲线创建

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:);
 }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值