そういうのがいいブログ

アプリ個人開発 まるブログ

アプリ開発覚え書き

【Unity】Animator 現在再生中のアニメーションクリップの名前を取得

Animatorメモ

現在再生中のアニメーションクリップの名前を取得 (ステート名ではない)

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

public class Animetest : MonoBehaviour
{
    [SerializeField] private Animator animator;//Animator型の変数を宣言 Animatorコンポーネントをアタッチしておく

    private AnimatorClipInfo[] animator_clipinfo1;//AnimatorClipInfo型の変数を宣言
    private string clip_name;//string型の変数を宣言 アニメーションクリップ名前取得用


    void Start()
    {
        
        animator_clipinfo1 = animator.GetCurrentAnimatorClipInfo(0);//現在のアニメーションクリップの情報を取得 引数0はレイヤーの番号

        clip_name = animator_clipinfo1[0].clip.name;//名前を取得
        
        Debug.Log(clip_name);//コンソールに表示
    }
}