Component.GetComponents 获取组件列表


function GetComponents (type : Type) : Component[]

Description描述

Returns all components of Type type in the GameObject.

在游戏物体返回全部Type类型组件。

  • C#

  • JavaScript

using UnityEngine;using System.Collections;public class example : MonoBehaviour {public HingeJoint[] hingeJoints;public void Awake() {hingeJoints = GetComponents<HingeJoint>();foreach (HingeJoint joint in hingeJoints) {joint.useSpring = false;}}}
// Disable the spring on all HingeJoints in this game object//在这个游戏物体禁用全部铰链关节上的弹簧var hingeJoints : HingeJoint[];hingeJoints = GetComponents (HingeJoint);for (var joint : HingeJoint in hingeJoints) {joint.useSpring = false;}


,