关于Time.timeScale的一些理解

总结如下:
1.timeScale不影响Update和LateUpdate,会影响FixedUpdate
2.timeScale不影响Time.realtimeSinceStartup,会影响Time.timeSinceLevelLoad和Time.time
3.timeScale不影响Time.fixedDeltaTime和Time.unscaleDeltaTime,会影响Time.deltaTime

测试代码如下:

using UnityEngine;  
using System.Collections;   
public class TestTimeScale : MonoBehaviour {  
    // Update is called once per frame  
    void Update ()   
    {  
        if (Input.GetKeyDown(KeyCode.Q)) Time.timeScale = 0;  
        if (Time.timeScale == 0)  
        {  
            print("Update");  
            print("Time.time:" + Time.time);  
            print("Time.timeSinceLevelLoad:" + Time.timeSinceLevelLoad);  
            print("Time.realtimeSinceStartup:" + Time.realtimeSinceStartup);    
            print("Time.deltaTime:" + Time.deltaTime);  
            print("Time.fixedDeltaTime:" + Time.fixedDeltaTime);  
            print("Time.unscaledDeltaTime:" + Time.unscaledDeltaTime);  
        }  
        //print("Time.timeSinceLevelLoad:" + Time.timeSinceLevelLoad);  
    }    
    void LateUpdate()  
    {  
        if (Time.timeScale == 0) print("LateUpdate");  
    }    
    void FixedUpdate()  
    {  
        if (Time.timeScale == 0) print("FixedUpdate");  
    }  
} 

再次总结:
当想代码受timeScale控制时(如暂停、加速),可以把代码放在FixedUpdate中,又或者跟Time.time或Time.deltaTime扯上关系;否则,可以用Time.realtimeSinceStartup(类似正常状态下的Time.time)和Time.unscaleDeltaTime(类似正常状态下的Time.deltaTime)

你可能感兴趣的:(关于Time.timeScale的一些理解)