【发布时间】:2015-11-04 23:38:13
【问题描述】:
如何检查特定动画是否已在 Unity 中播放完毕,然后执行操作? [C#] 我没有使用动画师。
【问题讨论】:
-
不确定您添加的“我没有使用动画师”如何使 Andrea 的响应无效,因为
IsPlaying是Animation的属性,而不是Animator...?
如何检查特定动画是否已在 Unity 中播放完毕,然后执行操作? [C#] 我没有使用动画师。
【问题讨论】:
IsPlaying 是 Animation 的属性,而不是 Animator...?
发件人: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 在他的帖子中所说:Animation-IsPlaying 几乎是您所需要的,因为您不使用 Animator。检查Animation 看看你可以使用的其他甜蜜的东西。
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() 所以如果你能详细说明我会编辑我的帖子。
【讨论】: