Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Component.GetComponents

public Component[] GetComponents(Type type);

Parameters

type The type of Component to retrieve.

Description

Returns all components of Type type in the GameObject.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public HingeJoint[] hingeJoints; void Example() { hingeJoints = GetComponents<HingeJoint>(); foreach (HingeJoint joint in hingeJoints) { joint.useSpring = false; } } }

public T[] GetComponents();

Description

Generic version. See the Generic Functions page for more details.