Jump--InAir.anim Jump--Jump.anim Locomotion--Run_N.anim Locomotion--Run_N_Land.anim Locomotion--Run_S.anim Locomotion--Walk_N.anim Locomotion--Walk_N_Land.anim Stand--Idle.anim
















OnFootstep()関数を定義しているのは、これを定義させずに動作させると 「animation "Walk-N" の receiver の "OnFootstep" がない」という警告がでるためである。 「足音を鳴らす」などのことをするために用意する関数のようだ。
| PlayerMoveAnim.cs |
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
[RequireComponent(typeof(PlayerInput))]
public class PlayerMoveAnim : MonoBehaviour
{
[SerializeField] private float velocity = 1.3f;
private Animator animator;
private CharacterController charController;
void Start()
{
charController = gameObject.GetComponent<CharacterController>();
animator = gameObject.GetComponent<Animator>();
}
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(h, 0, v);
float MovingSpeed = velocity * moveDirection.magnitude;
if (MovingSpeed > 0.1f)
{
animator.SetFloat("MovingSpeed", MovingSpeed);
} else
{
animator.SetFloat("MovingSpeed", 0.0f);
}
// Debug.Log(MovingSpeed);
transform.LookAt(transform.position + moveDirection);
moveDirection.y += Physics.gravity.y;
charController.Move(velocity * Time.deltaTime * moveDirection);
}
// for animation "Walk_N"
public void OnFootstep()
{
Debug.Log("Footstep event triggered");
}
}
|

動作させると、人の向きだけ変わって、アニメーションしないように見えるが、 4秒の変化時間が設定されているだけで、長く動作しているとアニメーションが開始される。



Unity プロジェクトの作成環境:
PC: minisforum um680
OS: Windows 11
Unity Hub: 3.12.1
Unity: 6000.0.50f1 (Intel)