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。 –