Unity3D常用API之工具类(Screen,Time,Mathf)

本文章内容来自于擅码网Unity3D****:http://www.mkcode.net/


Unity3D常用API之工具类(Screen,Time,Mathf)

代码:
public class ToolsClass : MonoBehaviour
{
    private float num = 0;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        // 屏幕类
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("屏幕高度:" + Screen.height);
            Debug.Log("屏幕宽度:" + Screen.width);
        }

        // 时间类
        //Debug.Log(Time.time); // 游戏运行时间
        //Debug.Log(Time.deltaTime); // 渲染一帧的时间
        //Time.timeScale = 1; // 时间缩放,控制游戏速度 暂停:0

        // 数学类
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log(Mathf.Abs(-7)); // 求绝对值
            Debug.Log(Mathf.Max(-7,-3)); // 求最大值
            Debug.Log(Mathf.Min(-7, -3)); // 求最小值
            Debug.Log(Mathf.Round(2.6f)); // 四舍五入

            Debug.Log(Mathf.Lerp(10, 10, 0.7f)); // 差值运算 目的“平滑过渡”
        }

        // 一个数从0,插值到10
        num = Mathf.Lerp(num, 10, Time.deltaTime);
        Debug.Log(num);
    }
}
图:

Unity3D常用API之工具类(Screen,Time,Mathf)