关于动画的播放、获取该对象的所有动画名、当前名及时间长度
private Animator animator;
private AnimationClip[] animationClip;
void Start()
{
animator = GetComponent<Animator>();
animationClip = animator.runtimeAnimatorController.animationClips;
Debug.Log("该对象有" + animationClip.Length + "个动画");
foreach(AnimationClip a in animationClip)//遍历获取所有该对象的动画名
{
Debug.Log(a.name);
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("按下A");
animator.Play(animationClip[0].name); //播放动画
animator.Update(0); //刷新0层的动画,默认新建的动画在0层。
GetAnimatorInfo();
}
if (Input.GetKeyDown(KeyCode.B))
{
Debug.Log("按下B");
animator.Play(animationClip[1].name);
animator.Update(0);
GetAnimatorInfo();
}
}
void G