Unity 6.3
0 онлайн 58 гостей 3 в системе
Вход

GameObject.AddComponent

Declaration

public Component AddComponent(Type componentType);

Описание

Добавление компонента указанного типа в GameObject.

Нет соответствующего метода для удаления компонента из GameObject. Чтобы удалить компонент, используйте Object.Destroy.

using UnityEngine;
using System.Collections;

public class AddComponentExample : MonoBehaviour { void Start() { SphereCollider sc = gameObject.AddComponent(typeof(SphereCollider)) as SphereCollider; } }

Дополнительные ресурсы: Component, Object.Destroy

Declaration

public T AddComponent();

Описание

Общая версия этого метода.

using UnityEngine;
using System.Collections;

public class AddComponentExample : MonoBehaviour { void Start() { SphereCollider sc = gameObject.AddComponent<SphereCollider>(); } }

Дополнительные ресурсы: Component, Object.Destroy

Declaration

Obsolete public Component AddComponent(string className);

Описание

Добавляет к GameObject компонент с указанным именем класса.

Устаревший: Используйте AddComponent(Type) или общий вариант этого метода.