Skip to content

Instantly share code, notes, and snippets.

@makochang
Created November 15, 2022 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makochang/dc21d85117b31ac053074cbc34e942c2 to your computer and use it in GitHub Desktop.
Save makochang/dc21d85117b31ac053074cbc34e942c2 to your computer and use it in GitHub Desktop.
アニメーション残り0.25秒だけ入力を受け付ける
using UnityEngine;
public class InputTime : MonoBehaviour
{
public Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
AnimatorClipInfo[] animatorClipInfos = animator.GetCurrentAnimatorClipInfo(0);
//ステートのアニメーションの長さ
float totalAnimTime = animatorClipInfos[0].clip.length;
//現在何秒再生したか
float currentAnimTime = totalAnimTime * animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
//アニメーションが残り1秒以内なら
if (totalAnimTime-currentAnimTime <= 0.25f)
{
Debug.Log(animatorClipInfos[0].clip.name + "入力受付");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment