how to remove a component in unity code example
Example 1: how to remove a component from an object in unity
Destroy(GetComponent());
Example 2: unity remove component in script
Destroy (gameObject);
Example 3: unity3d remove component
// Kills the game object
Destroy (gameObject);
// Removes this script instance from the game object
Destroy (this);
// Removes the rigidbody from the game object
Destroy (rigidbody);
// Kills the game object in 5 seconds after loading the object
Destroy (gameObject, 5);
// When the user presses Ctrl, it will remove the script
// named FooScript from the game object
function Update () {
if (Input.GetButton ("Fire1") && GetComponent (FooScript))
Destroy (GetComponent (FooScript));
}
Example 4: unity remove component
//Use Destroy() for removing components