[Unity基础]游戏暂停下播放角色与粒子动画

原文链接:http://www.unitymanual.com/thread-21763-1-1.html


代码如下:

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

    //要测试的角色和粒子
    public Animator animator;
    public ParticleSystem particleSystem;

    // Update is called once per frame
	void Update () 
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            //当Time.timeScale等于0时,角色动画会暂停
            animator.updateMode = AnimatorUpdateMode.Normal;
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            //当Time.timeScale等于0时,角色动画不会暂停
            animator.updateMode = AnimatorUpdateMode.UnscaledTime;
        }

        if (Time.timeScale == 0)
        {
            //当Time.timeScale等于0时,粒子动画不会暂停
            particleSystem.Simulate(Time.unscaledDeltaTime, false, false);
        }
	}

}


你可能感兴趣的:(TimeScale)