---
title: "Destroy"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/destroy-i?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting-old.md?language=en"
unit_title: "Beginner Scripting"
unit_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting?language=en"
standalone_markdown_url: "https://learn.unity.com/tutorial/destroy-i.md?language=en"
previous_title: "Linear Interpolation"
previous_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/linear-interpolation?language=en"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/linear-interpolation.md?language=en"
next_title: "GetButton and GetKey"
next_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getbutton-and-getkey?language=en"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getbutton-and-getkey.md?language=en"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/destroy-i.md?language=en&version=4.x"
last_updated: "2026-08-04T14:22:47.000Z"
---

# Destroy

Discover how to use the Destroy() function to remove GameObjects and components at runtime.

How to use the Destroy() function to remove GameObjects and Components at runtime.

This tutorial is included in the [Beginner Scripting project](https://learn.unity.com/project/beginner-gameplay-scripting).

Previous: [Linear Interpolation](https://learn.unity.com/tutorial/linear-interpolation?projectId=5c8920b4edbc2a113b6bc26a)

Next: [GetButton and GetKey](https://learn.unity.com/tutorial/getbutton-and-getkey?projectId=5c8920b4edbc2a113b6bc26a)

## 1. Destroy

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/0907b47e-e77d-49bf-a790-75887d6e5138_U_Beginner_14_Destroy.mp4)

## **DestroyBasic**

```csharp
using UnityEngine;
using System.Collections;

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

## **DestroyOther**

```csharp
using UnityEngine;
using System.Collections;

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

## **DestroyComponent**

```csharp
using UnityEngine;
using System.Collections;

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