GameObjectExtensions.GetRequiredComponent<T>

Extension Method in GameObjectExtensions

Declaration

public static T GetRequiredComponent<T>(this GameObject gameObject)
    where T : Component

Description

Gets the specified component from the game object. If the component does not exist, then it will be added to the game object.

Type Parameters

TThe type of component to get.

Parameters

gameObjectThe game object to get the component from.

Returns

TThe component reference.