Files
3d-qiaozha/Assets/Scripts/PlayerAniControl.cs
2026-03-10 10:07:11 +08:00

46 lines
1.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<Animator>();
}
// 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");
}*/
}
}