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

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;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,537评论 0 17
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,973评论 19 139
  • Animation Animation类是所有动画(scale、alpha、translate、rotate)的基...
    四月一号阅读 1,936评论 0 10
  • 1.感恩神的拣选让我能够认识上帝。2.感恩神医治我的家人,让我能有一个健康和睦的家庭。3.感恩父母辛辛苦苦的抚养我...
    sunlin1234阅读 684评论 2 2