# Deleting objects one by one

**URL:** https://discussions.unity.com/t/deleting-objects-one-by-one/182851
**Category:** Questions & Answers
**Created:** [February 22, 2017, 8:06am UTC](https://discussions.unity.com/t/deleting-objects-one-by-one/182851 "2017-02-22T08:06:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gaming-Dudester](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gaming-dudester/32/345980_2.png) [@Gaming-Dudester](https://discussions.unity.com/u/Gaming-Dudester)
#### Post date: [February 22, 2017, 8:06am UTC](https://discussions.unity.com/t/deleting-objects-one-by-one/182851/1 "2017-02-22T08:06:34Z")

</div>

So i have a row of cubes. I want to collide into them and when i do they get destroyed.

void OnTriggerEnter(Collider coll)  
{

```
  if(coll.gameObject.tag == "Buns")
 {
     incube = true;
 }

```

}

void Update()  
{

```
if (Input.GetKeyDown(Keycode.lol)&& incube == true)

```

{  
//but how to distroy object? Destroy(gameObject); yea i know but how to tell what im colliding with at the moment. I dont wanna break every cube at once. Also they randomly spawn so dont say “Give each a number” or something lol  
}

}

How to delete the object im colliding with when i push buttons

---

<div class="post-metadata">

### Author: ![SamElTerrible](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@SamElTerrible](https://discussions.unity.com/u/SamElTerrible)
#### Post date: [February 22, 2017, 9:16am UTC](https://discussions.unity.com/t/deleting-objects-one-by-one/182851/2 "2017-02-22T09:16:16Z")

</div>

Use OnCollisionEnter(), in a way such as:

```
void OnCollisionEnter(Collider other){
          if(other.tag == "buns"){
              Destroy(other.gameObject);
       }
}

```

When you are within the OnCollision loop, you can access both the gameobject whose script this is by using the keyword **this** or the other gameobject using the name that you give to its collider. In this case **other**.

Hope it helps!
