KITASENJU DESIGN BLOG

memo, html, javascript, unity

Animatorの時間

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharaBase : MonoBehaviour
{

    [SerializeField] protected Animator _animator;

    void Update()
    {
        CheckAnim();
    }

    void CheckAnim()
    {
        if (_animator == null) return;
        
        AnimatorStateInfo stateInfo = _animator.GetCurrentAnimatorStateInfo(0);
        float normalizedTime = stateInfo.normalizedTime;
        float currentTime = normalizedTime * stateInfo.length;
        _time = currentTime % stateInfo.length;

        if (_time - _pastTime < 0)
        {
            Debug.Log("anim start");
        }

        _pastTime = _time;
        // Debug.Log("現在の再生時間: " + currentTime%stateInfo.length);        
        
    }
}


"FOOTER"