using UnityEngine; using System.Collections; public class PlayerAnimation : MonoBehaviour { float ver; private Animator ani; void Awake() { ani = GetComponent<Animator> (); } void Update() { ver = Input.GetAxis ("Vertical"); //设置动画状态机参数 // ani.SetInteger ("Number",(int)Mathf.Abs (ver)); ani.SetInteger (HashIDs.instance.Number,(int)Mathf.Abs (ver)); //前键,人物朝前,后键,人物朝后 if (ver > 0) { transform.eulerAngles = Vector3.zero; } else if(ver < 0){ transform.eulerAngles = Vector3.up * 180; } //按下空格,玩家喊叫 if (Input.GetKeyDown (KeyCode.Space)) { ani.SetTrigger ("Shout"); } } }
上面的这个脚本挂载人物身上达到控制任务执行动画的效果
接下来就是设置动画的速度赋值
using UnityEngine; using System.Collections; public class HashIDs : MonoBehaviour { public static HashIDs instance; void Awake() { instance = this; } public int Speed; public int Number; public int Idle; public int Run; void Start() { Speed = Animator.StringToHash ("Speed"); Number = Animator.StringToHash ("Number"); Idle = Animator.StringToHash ("Idle"); Run = Animator.StringToHash ("Run"); } }
时间: 2024-11-03 21:34:52