Component[] componments2 = gameObject.GetComponents<Component>(); Debug.Log("componments2的长度:" + componments2.Length); for (int i = 0; i < componments2.Length; i++) { Debug.Log("组件的名字:" + componments2[i]); //componments2[i] 是拿到组件的名字, componments2[i].name是拿到组件所在的游戏对象的名字 }