0
所以有两种方式 [我通过搜索得到,如果有任何其他方式请分享]做到这一点。如何知道动画剪辑已完成?
- IsPlaying模块属性(例1)
- 动画时间(例2)
两个,我不想因为第一种方式是使用使用协同例程我不想要使用 和第二个是使用时间如果增加动画速度则时间将无法正常工作,从而影响代码。
实施例1对
public class AnimationSequancePlayer : MonoBehaviour {
public Animation animation; // The animation we want to play the clips in.
public AnimationClip[] animationClips; // The animation clips we want to play in order.
int _currentClipOffset;
void Start()
{
foreach (AnimationClip clip in animationClips)
{
animation.AddClip(clip, clip.name); // Make sure the animation player contains all of our clips.
}
PlaySequence();
}
public void PlaySequence()
{
_currentClipOffset = 0; // Reset the index to start at the beginning.
PlayNextClip();
}
public void StopSequence()
{
animation.Stop();
StopAllCoroutines();
}
void PlayNextClip()
{
animation.Play(animationClips[_currentClipOffset].name); // Play the wanted clip
if (_currentClipOffset != animationClips.Length)
{ // Check if it's the last animation or not.
StartCoroutine(WaitForAnimationEnd(() => PlayNextClip())); // Listen for end of the animation to call this function again.
_currentClipOffset++; // Increase index for next time;
}
}
IEnumerator WaitForAnimationEnd(Action onFinish)
{
while (animation.isPlaying)
{ // Check if the animation is playing or not
yield return null;
}
if (onFinish != null) { onFinish(); } // Call the function give in parameter.
}
}
实施例2
if (GetComponent<Animation>()["Move Crane"].time >= 3f)
{
///logic after animation reached at specified time specified time
}
您是否试过_动画Events_? – Kay
nope这是什么 –
我正在使用max动画不unity3d。 –