Obsolete public Component AddComponent (string className);

Descripción

Agrega una clase componente llamada className al game object.

GameObject.AddComponent with string argument has been deprecated. Use AddComponent(Type) or the generic version instead.


public Component AddComponent (Type componentType);

Descripción

Agrega una clase componente del tipo componentType al game object. Los usuarios de C# pueden usar una versión genérica.

using UnityEngine;
using System.Collections;

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

Note that there is no RemoveComponent(), to remove a component, use Object.Destroy.


public T AddComponent ();

Descripción

Generic version of this method.

using UnityEngine;
using System.Collections;

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