文档

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.