Destroy A Game Object In a Certain Posistion

Hi, I’m fairly new to Unity so I’m wondering how I can destroy a game object that is, for example, 1x,2y,3z.

This is in C#.


public void DestroyAtPosition(Vector3 Position){
     GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>() ; // Gets all gameobjects in scene
     foreach(object go in allObjects){ // Loops through them all
          if (go.transform.position == Position){ // Checks if the gameobject position is the one that needs to get deleted
              Destroy(go); // Deletes gameobject


To your script.
Then use


To call the function.

Hopefully this helps,

  • Jabez.