using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Animatest : MonoBehaviour
{
public float timeSlider;
public Animator _animator;
AnimationClip nowPlay;
public Dictionary<string, AnimationClip> animationClips;
void Awake()
{
//animator.get
animationClips = new Dictionary<string, AnimationClip>();
_animator = GetComponent<Animator>();
if (_animator != null)
{
var animations = _animator.runtimeAnimatorController.animationClips;
for (int i = 0; i < animations.Length; ++i)
{
var anim = animations[i];
animationClips[anim.name] = anim;
}
if (nowPlay == null && animationClips.Count > 0)
{
nowPlay = animationClips.ElementAt(0).Value;
_animator.Play(nowPlay.name, 0, 0.001f);//相当于一开始,即暂停
}
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
_animator.Play(nowPlay.name, 0, timeSlider);
}
}