TryGetComponent

public static bool TryGetComponent<T>(this GameObject gameObject, out T outComponent) ;

存在している場合にコンポーネントを取得する。

型パラメーター名 説明 型制約
T コンポーネントの型
パラメーター名 説明
gameObject GameObject
outComponent 見つかったコンポーネントの出力引数

コンポーネントが見つかった場合にtrueを返す。

public static bool TryGetComponent<T>(this Component component, out T outComponent) ;

存在している場合にコンポーネントを取得する。

型パラメーター名 説明 型制約
T コンポーネントの型
パラメーター名 説明
component Component
outComponent 見つかったコンポーネントの出力引数

コンポーネントが見つかった場合にtrueを返す。