这里查看物体自带动画,并可以进行切割。
Animation组件就是控制播放动画。
public const string ANIM_NAME0 = "Take 001"; public const string ANIN_NAME1 = "Take 0010"; private GameObject obj = null; void Start () { obj = GameObject.Find("yh_mx"); obj.animation.wrapMode = WrapMode.Default; } // Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.A)) { obj.animation.Play(ANIM_NAME0); } if(Input.GetKeyDown(KeyCode.B)) { obj.animation.Play(ANIN_NAME1); } }
很多时候还用到动画倒播。
void OnGUI (){ if (GUI.Button(new Rect(0, 0, 100, 50), "正常")) { animation["Take 002"].speed = 1; animation.Play("Take 002"); } if (GUI.Button(new Rect(0, 120, 200,50), "倒播")) { animation["Take 002"].speed = -1; animation["Take 002"].time = animation["Take 002"].length; animation.Play("Take 002"); } }