function GetComponents (type : Type) : Component[]
Description描述
Returns all components of Type type in the GameObject.
返回这个游戏物体上的所有类型为type的组件。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public HingeJoint[] hingeJoints;
public void Awake() {
hingeJoints = gameObject.GetComponents<HingeJoint>();
foreach (HingeJoint joint in hingeJoints) {
joint.useSpring = false;
}
}
}
// Disable the spring on all HingeJoints
// in this game object
// 使这个游戏物体上的所有HingeJoints上的spring不可用.
var hingeJoints : HingeJoint[];
hingeJoints = gameObject.GetComponents (HingeJoint);
for (var joint : HingeJoint in hingeJoints) {
joint.useSpring = false;
}