Unity 3d 幾種Update


本篇簡單介紹Unity3d中幾種Update方法的區別。

Update方法

所有

Update

Update是在每次渲染新的一幀的時候才會調用,也就是說,這個函數的更新頻率和設備的性能有關以及被渲染的物體(可以認為是三角形的數量)。在性能好的機器上可能fps 30,差的可能小些。這會導致同一個游戲在不同的機器上效果不一致,有的快有的慢。因為Update的執行間隔不一樣了。

FixedUpdate

FixedUpdate是在固定的時間間隔執行,不受游戲幀率的影響。Tips:在處理Rigidbody的時候最好用FixedUpdate

FixedUpdate設置:Edit --> Project Settings --> Time

outPut

LateUpdate

LateUpdate是在所有Update函數調用后被調用。這可用於調整腳本執行順序。

UpdateFixedUpdate的區別

  • FPS = 2;

using UnityEngine;
using System.Collections;

public class FPS : MonoBehaviour {
	
	void Awake() {
		Application.targetFrameRate = 2;
	}

	void Update () {
		
		Debug.Log ("Update");
		
	}
	
	void FixedUpdate () {
		
		Debug.Log ("FixedUpdate");
		
	}
}


outPut

  • FPS = 60;

using UnityEngine;
using System.Collections;

public class FPS : MonoBehaviour {
	
	void Awake() {
		Application.targetFrameRate = 60;
	}

	void Update () {
		
		Debug.Log ("Update");
		
	}
	
	void FixedUpdate () {
		
		Debug.Log ("FixedUpdate");
		
	}
}


outPut


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM