美文网首页
unity 动画(Animation)暂停 和 特效(Parti

unity 动画(Animation)暂停 和 特效(Parti

作者: 红定义 | 来源:发表于2017-03-07 08:26 被阅读0次

using UnityEngine;

using System.Collections;

public class FbxTest : MonoBehaviour

{

public Animator animator;

public Animation animation;

public ParticleSystem ps;

void Update()

{

if (Input.GetKeyDown(KeyCode.Space))

{

//方法1

string aniName = GetCurrentPlayingAnimationClip(animation);

if (animation[aniName].speed > 0)

{

animation[aniName].speed = 0;

ps.Pause();

}

else

{

animation[aniName].speed = 1;

ps.Play();

}

//方法2

if (null != animator)

{

AnimationInfo[] infs = animator.GetCurrentAnimationClipState(0);

foreach (AnimationInfo info in infs)

{

if (animator.speed > 0)

{

Debug.Log("animator.speed = 0;");

animator.speed = 0;

ps.Pause();

}

else

{

Debug.Log("animator.speed = 1;");

animator.speed = 1;

ps.Play();

}

}

}

}

}

public string GetCurrentPlayingAnimationClip(Animation go)

{

if (go == null)

{

return string.Empty;

}

foreach (AnimationState anim in go)

{

if (go.IsPlaying(anim.name))

{

return anim.name;

}

}

return string.Empty;

}

}

相关文章

网友评论

      本文标题:unity 动画(Animation)暂停 和 特效(Parti

      本文链接:https://www.haomeiwen.com/subject/knmpgttx.html