如何从Animator中检索当前播放的动画?

问题描述 投票:-2回答:1

我想检查一个动画是否在播放,所以你能帮我检索当前播放的动画名称。

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

public class AIM : MonoBehaviour
{
    public Animator play;

    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {  
      //Debug.Log(play.GetCurrentAnimatorClipInfo(0).clip.name);
    }
}

Animator.GetCurrentAnimatorClipInfo 我试过了 play.GetCurrentAnimatorClipInfo(0).clip.name 但它却抛出了一个错误。

'AnimatorClipInfo[]' does not contain a definition for 'clip'

unity3d
1个回答
1
投票

这是因为你在访问数组。GetCurrentAnimatorClipInfo(0)返回一个数组。你需要访问数组元素来获取信息,像这样。

play.GetCurrentAnimatorClipInfo(0)[0].clip.name
© www.soinside.com 2019 - 2024. All rights reserved.