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.
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.
Generic version of this method.
using UnityEngine; using System.Collections;
public class AddComponentExample : MonoBehaviour { void Start() { SphereCollider sc = gameObject.AddComponent<SphereCollider>() as SphereCollider; } }