Beginner Scripting: Destroy
In this weeks Coding Task it looked at using Destroy to destroy objects and components in a game. This can be used for a multitude of things in the game. Destroying an object will remove the script all together with the object however and this is something that should be noted. You can also destroy mesh renderer component which results in the object not visibly being in the scene however the object is not there. A time delay can also be added to this function.
The script is as follows
public class DestroyBasic : MonoBehaviour { void Update () { if(Input.GetKey(KeyCode.Space)) { Destroy(gameObject); } } }
Comments
Post a Comment