Monday, January 8, 2018
Unity Remove Component or Game Object
Unity Remove Component or Game Object
The way to remove game object you want is simple easy what you need to add is the piece of function and your object.
The public static function Destroy() is a key its Removes a gameobject, component or asset. reference
The public static function Destroy() is a key its Removes a gameobject, component or asset. reference
Examples:
// 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));
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.