Project
Beginner Gameplay Scripting
Destroy
Tutorial
Beginner
5 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Destroy
Summary
How to use the Destroy() function to remove GameObjects and Components at runtime.
Language
English
Recommended Unity Versions
4
1.
Destroy

DestroyBasic

using UnityEngine; using System.Collections; public class DestroyBasic : MonoBehaviour { void Update () { if(Input.GetKey(KeyCode.Space)) { Destroy(gameObject); } } }

DestroyOther

using UnityEngine; using System.Collections; public class DestroyOther : MonoBehaviour { public GameObject other; void Update () { if(Input.GetKey(KeyCode.Space)) { Destroy(other); } } }

DestroyComponent

using UnityEngine; using System.Collections; public class DestroyComponent : MonoBehaviour { void Update () { if(Input.GetKey(KeyCode.Space)) { Destroy(GetComponent<MeshRenderer>()); } } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
GetButton and GetKey
Tutorial
Beginner
5 Mins
Unity Technologies