Version: 5.4
public Component GetComponent (Type type);

Parámetros

type El tipo de Component para recuperar.

Descripción

Devuelve un componente de tipo type si el game object tiene a alguno adjuntado, o null si no lo tiene.

// Disable the spring on the HingeJoint component.
        HingeJoint hinge = GetComponent<HingeJoint>();
        hinge.useSpring = false;

public T GetComponent ();

Descripción

Versión genérica. Para más detalles, mira la página de Funciones genéricas.


public Component GetComponent (string type);

Descripción

Devuelve el componente que sea de tipo type si el game object tiene a alguno adjuntado, o null si no lo tiene.

It is better to use GetComponent with a Type instead of a string for performance reasons. Sometimes you might not be able to get to the type however, for example when trying to access a C# script from Javascript. In that case you can simply access the component by name instead of type. Example:

// Disable the spring on the HingeJoint component.
        HingeJoint hinge = GetComponent("HingeJoint") as HingeJoint;
        hinge.useSpring = false;