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

posted @ 2018-09-17 14:21  可爱的黑精灵  阅读(6525)  评论(0编辑  收藏  举报