[英]Check if animation has finished playing?
如何检查特定动画是否已在Unity中完成播放,然后执行动作? [C#]我没有使用动画师。
来自: http : //answers.unity3d.com/questions/52005/destroy-game-object-after-animation.html
要从动画编辑器执行动作...
-使用简单的公共函数创建脚本,该脚本将销毁对象。 例如
public class Destroyable : MonoBehaviour
{
public void DestroyMe()
{
Destroy(gameObject);
}
}
-将该脚本添加到要销毁的动画对象中。
-在动画编辑器中,将动画洗涤器移动到动画的末尾。
-使用动画工具栏中的“添加事件”按钮
-在“编辑动画事件”对话框的功能下拉列表中选择“ DestroyMe”。
-现在应该播放动画,运行“ DeleteMe”功能,并销毁对象/执行操作。
我已经使用过几次这种方法,对于动画中的某些事情非常有用:)
您应该检查Animation.IsPlaying值。
从文档:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Animation anim;
void Start() {
anim = GetComponent<Animation>();
}
void OnMouseEnter() {
if (!anim.IsPlaying("mouseOverEffect"))
anim.Play("mouseOverEffect");
}
}
就像安德里亚(Andrea)在他的帖子中所说的那样: 动画-IsPlaying几乎是您需要的,因为您不使用Animator。 选中动画以查看其他可以使用的甜食。
using UnityEngine;
using UnityEngine.Collections;
public class ExampleClass : MonoBehaviour
{
Animation anim;
void Start()
{
anim = GetComponent<Animation>();
}
//In update or in another method you might want to check
if(!anim.isPlaying("StringWithAnimationClip") //or anim.clip.name
//Do Something
}
您也可以使用anim.Stop()强制停止动画;
现在,您评论了您不想使用isPlaying(),因此请您详细说明一下,我将编辑我的帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.