animator 新动画
Posted huang--wei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了animator 新动画相关的知识,希望对你有一定的参考价值。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimatorCon : MonoBehaviour { Animator ani; // Use this for initialization void Start () { ani = GetComponent<Animator>(); } // Update is called once per frame void Update () { float h = Input.GetAxis("Horizontal");//控制移动 float v = Input.GetAxis("Vertical"); transform.Translate(h*Time.deltaTime,0,v*Time.deltaTime); if (h<0) { transform.localScale = new Vector3(-1,1,1);//反向移动 } else { transform.localScale = Vector3.one; } if (h!=0||v!=0) { ani.SetBool("IsRun",true); } else { ani.SetBool("IsRun", false); } if (Input.GetKeyDown(KeyCode.Q)) { ani.SetBool("IsAttack",true); } else { ani.SetBool("IsAttack", false); } } }
2.int类型
using System.Collections; using System.Collections.Generic; using UnityEngine; //animator动画状态机int类型的控制 public class DragonControlor : MonoBehaviour { Animator ani; // Use this for initialization void Start () { ani = GetComponent<Animator>(); } public void GetButtonQ() { ani.SetInteger("com", 1);//对paiameters进行设置 } public void GetButtonW() { ani.SetInteger("com", -1);//对paiameters进行设置 ani.SetInteger("con", 1); } public void GetButtonE() { ani.SetInteger("con", -1);//对paiameters进行设置 } // Update is called once per frame void Update () { AnimatorStateInfo start = ani.GetCurrentAnimatorStateInfo(0);//判断当前动画状态 if (start.IsName("dragon_land_on_ground")) { ani.SetInteger("com", 0);//让它返回 } if (start.IsName("dragon_die")) { ani.SetInteger("com", 0); } if (start.IsName("dragon_loop_da_loop")) { ani.SetInteger("con", 0); } } }
AnimatorStateInfo aniSta= ani.GetCurrentAnimatorStateInfo(0);//获得当前层的动画片段状态信息 if (h != 0 || v != 0) { ani.SetBool("IsWalk", true); if (Input.GetKey(KeyCode.LeftShift)) { ani.SetBool("IsRun", true); } else { ani.SetBool("IsRun", false); } } else { if (aniSta.IsName("run"))//判断是否正在播放此动画 { ani.SetBool("IsRun", false); } ani.SetBool("IsWalk", false); }
以上是关于animator 新动画的主要内容,如果未能解决你的问题,请参考以下文章