using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerAniControl : MonoBehaviour { private Animator anim; // Start is called before the first frame update void Start() { anim = GetComponent(); } // Update is called once per frame void Update() { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); // 判定是否行走:输入值的模长超过死区 bool isWalking = Mathf.Sqrt(h * h + v * v) > 0.1f; if (Input.GetKey(KeyCode.W)) { if (Input.GetKey(KeyCode.LeftShift)) { anim.Play("HumanF@Run01_Forward"); return; } anim.Play("HumanM@Walk01_Forward"); return; } // 给Animator设置布尔参数,驱动Idle↔Walk // anim.SetBool("IsRunning", isWalking); /* // 2. 检测攻击输入(鼠标左键) if (Input.GetMouseButtonDown(0)) { // 触发攻击参数,状态机自动切Attack anim.SetTrigger("Attack1"); } if (Input.GetMouseButtonDown(1)) { // 触发攻击参数,状态机自动切Attack anim.SetTrigger("Attack2"); }*/ } }