ドキュメント

Unity Engine

Unity Engine

AddComponent

Adds a component to the game object and registers an undo operation for this action.
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

AddComponent(GameObject, Type)

Adds a component to the game object and registers an undo operation for this action.
public static Component AddComponent(GameObject gameObject, Type type)

Parameters

gameObject

The game object you want to add the component to.

type

The type of component you want to add.

Returns

Type

Description

ComponentThe newly added component.

Remarks

If the undo is performed, the newly added component will be destroyed.

AddComponent<T>(GameObject)

Generic version.
public static T AddComponent<T>(GameObject gameObject) where T : Component

Parameters

gameObject

The game object you want to add the component to.

Returns

Type

Description

TThe newly added component.