Unity 游戏对象的组件列表

描述:

   1 个游戏对象,上面有 4 个组件, 如图:

  

 脚本 Test_01 的内容,如下:

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

public class Test_01 : MonoBehaviour {

    public List<Component> componentsList = new List<Component>();

    // Use this for initialization
    void Start () {
        Component[] componments = gameObject.GetComponents<Component>();
        componentsList = new  List<Component>(componments);
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

第一种情况: 运行Unity,List 里的顺序跟游戏对象的组件从上到下顺序一样.

 

第二种情况: 拖动任意一个组件,变化它的顺序,再运行,顺序还是一样.

 

  

原文地址:https://www.cnblogs.com/Peng18233754457/p/8798571.html