检查动画是否播放完毕?
Check if animation has finished playing?
如何检查 特定 动画是否已在 Unity 中播放完毕,然后执行动作? [C#] 我没有使用动画师。
您应该检查 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");
}
}
发件人:http://answers.unity3d.com/questions/52005/destroy-game-object-after-animation.html
要从动画编辑器执行动作...
-用一个简单的 public 函数创建一个脚本来销毁对象。例如
public class Destroyable : MonoBehaviour
{
public void DestroyMe()
{
Destroy(gameObject);
}
}
-将该脚本添加到您要销毁的动画对象中。
-在动画编辑器中,将动画滑块移动到动画末尾。
-使用动画工具栏中的'Add Event'按钮
-Select 'DestroyMe' 来自“编辑动画事件”对话框的功能下拉列表。
-现在您的动画应该播放,运行 'DeleteMe' 函数,并销毁 object/do 您的动作。
这个方法我用过几次,对动画中的某些东西派上了用场:)
正如 Andrea 在他的 post 中所说:Animation-IsPlaying is pretty much what you need since you don't use Animator. Check 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() 所以如果你可以请详细说明我会编辑我的 post。
如何检查 特定 动画是否已在 Unity 中播放完毕,然后执行动作? [C#] 我没有使用动画师。
您应该检查 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");
}
}
发件人:http://answers.unity3d.com/questions/52005/destroy-game-object-after-animation.html
要从动画编辑器执行动作...
-用一个简单的 public 函数创建一个脚本来销毁对象。例如
public class Destroyable : MonoBehaviour
{
public void DestroyMe()
{
Destroy(gameObject);
}
}
-将该脚本添加到您要销毁的动画对象中。
-在动画编辑器中,将动画滑块移动到动画末尾。
-使用动画工具栏中的'Add Event'按钮
-Select 'DestroyMe' 来自“编辑动画事件”对话框的功能下拉列表。
-现在您的动画应该播放,运行 'DeleteMe' 函数,并销毁 object/do 您的动作。
这个方法我用过几次,对动画中的某些东西派上了用场:)
正如 Andrea 在他的 post 中所说:Animation-IsPlaying is pretty much what you need since you don't use Animator. Check 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() 所以如果你可以请详细说明我会编辑我的 post。