Unity API常用方法和类学习笔记1

Unity API常用方法和类学习笔记1

------主要构架(Unity-Engine、GameObject、Component)

事件

一、事件执行顺序
在这里插入图片描述
二、测试代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class API01EventFunction : MonoBehaviour
{
    void Reset(){
        Debug.Log("Reset");//当脚本被附加到对象上时或被重置时
    }
    
    void Awake(){
        Debug.Log("Awake");
    }
    
    void OnEnable() {
        Debug.Log("OnEnable");//当脚本所在对象被重新可见时
    }
    
    void Start(){
        Debug.Log("Start");
    }
    
    void FixedUpdate(){
        Debug.Log("FixedUpdate");//每秒有固定的调用次数,所以运行时不受电脑性能的差别影响——适合用于控制物体的运动
    }
    
    void Update(){
        Debug.Log("Update");//不固定,调用次数随电脑运行-画面加载快慢影响
    }
    
    void LateUpdate() {
        Debug.Log("LateUpdate");//跟随Update(一致)
    }
    
    void OnApplicationPause() {
        Debug.Log("OnApplicationPause");
    }
    
    void OnDisable() {
        Debug.Log("OnDisable");//当物体不可见时
    }
    
    void OnApplicationQuit() {
        Debug.Log("OnApplicationQuit");//退出时
    }
    
    void OnDestoy() {
        Debug.Log("OnDestroy");
    }
}

类Time

一、静态变量

	void Update () {
        Debug.Log("Time.deltaTime" + Time.deltaTime);//每一帧的时间间隔约等于1/60秒
        Debug.Log("Time.fixedDeltaTime" + Time.fixedDeltaTime);//固定的间隔时间
        Debug.Log("Time.fixedTime" + Time.fixedTime);//从游戏开始到游戏结束
        Debug.Log("Time.frameCount" + Time.frameCount);//帧数
        Debug.Log("Time.realtimeSinceStartup" + Time.realtimeSinceStartup);//从游戏开始到游戏结束的时间(暂停时仍继续计时)
        Debug.Log("Time.smoothDeltaTime" + Time.smoothDeltaTime);//较平滑的间隔时间
        Debug.Log("Time.time" + Time.time);//与Time.fixedTime差不多
        Debug.Log("Time.timeScale" + Time.timeScale);//设置时间比例
        Debug.Log("Time.timeSinceLevelLoad" + Time.timeSinceLevelLoad);//以场景为基准,加载新场景时重新开始计时
        Debug.Log("Time.unscaledTime" + Time.unscaledTime);
        }

二、利用Time.realtimeSinceStartup测试函数是否太耗费性能

	void Start () {
        //利用Time.realtimeSinceStartup测试函数是否太耗费性能
        float time1 = Time.realtimeSinceStartup;
        for (int i = 0; i < runCount; i++)
        {
            Method1();
        }
        float time2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值