- 爲一個場景對象添加上三個腳本,在場景開始運行時,腳本中的Start方法將會按照腳本添加的順序來依次運行,而Update方法卻是完全相反
比如:有A1、A2、A3三個腳本,它們的添加順序是A1、A3、A2,那麼在場景運行時,程序運行順序是A1.Start()、A3.Start()、 A2.Start()、A2.Update()、A3.Update()、A1.Update()……,即使A1.Start()或A2.Update ()運算時間超過其它的方法,那麼其它的方法也會等待其運行完成後纔會開始運行之……
下面是三個腳本文件的例程:
jxxh01.cs- using UnityEngine;
- using System.Collections;
- public class jxxh01 : MonoBehaviour
- {
- // Use this for initialization
- void Start()
- {
- for (int temp02 = 0; temp02 < 5; temp02++)
- {
- for (int temp01 = 0; temp01 < 5; temp01++)
- {
- int a01 = 0;
- for (int temp = 0; temp < 50000; temp++)
- {
- a01++;
- a = a01;
- }
- a01 = 0;
- }
- }
- print(Time.time + " This is jxxh01 : " + a);
- }
- public int ForValue=10000;
- int a = 0;
- // Update is called once per frame
- void Update () {
- for (int temp = 0; temp < ForValue; temp++) { a = temp; }
- print(Time.time + " This is jxxh01 : " + a);
- }
- }
jxxh02.cs- using UnityEngine;
- using System.Collections;
- public class jxxh02 : MonoBehaviour
- {
- // Use this for initialization
- void Start()
- {
- for (int temp = 0; temp < 10000; temp++)
- {
- a++;
- }
- print(Time.time + " This is jxxh02 : " + a);
- }
- public int ForValue = 100;
- int a = 0;
- // Update is called once per frame
- void Update () {
- print(Time.time + " This is jxxh02 : " + a);
- }
- }
jxxh03.cs- using UnityEngine;
- using System.Collections;
- public class jxxh03 : MonoBehaviour
- {
- // Use this for initialization
- void Start()
- {
- for (int temp = 0; temp < 10000; temp++)
- {
- a++;
- }
- print(Time.time + " This is jxxh03 : " + a);
- }
- public int ForValue = 100;
- int a = 0;
- // Update is called once per frame
- void Update () {
- print(Time.time + " This is jxxh03 : " + a);
- }
- }
Unity 對運行順序,整體架構的理解,初學
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.