C# 如何在Unity C中等待动画完成#
我想在设置触发器后等待动画剪辑完成C# 如何在Unity C中等待动画完成#,c#,unity3d,animator,C#,Unity3d,Animator,我想在设置触发器后等待动画剪辑完成 private void Start() { anim = GetComponent<Animator>(); } private IEnumerator Die() { // Play the animation for getting suck in anim.SetTrigger("Shrink") // Wait for the current animation to finish
private void Start()
{
anim = GetComponent<Animator>();
}
private IEnumerator Die()
{
// Play the animation for getting suck in
anim.SetTrigger("Shrink")
// Wait for the current animation to finish
while (!anim.IsInTransition(0))
{
yield return null;
}
// Move this object somewhere off the screen
}
private void Start()
{
anim=GetComponent等待动画完成的方法是使用动画完成所需的时间,您可以在查看检查器的动画中找到该时间,您只需在触发动画后等待该时间即可
所以在你的例子中,它看起来是这样的:
private IEnumerator Die()
{
// Play the animation for getting suck in
anim.SetTrigger("Shrink")
yield return new WaitForSeconds(animationTime);
// Move this object somewhere off the screen
}
可以使用Unity的动画事件()
它们是可以放置在动画时间轴中的标记,允许您指定将调用的函数