Erasing a gameobject if you have the coordinates.

Hi, I have a cube that moves left and right (2D). It moves on a grid of cubes (so a cube at x = 1 and y = 1, another cube at x=2 and y = 1 and so on). All the cubes are 1 by 1 by 1. My question is, if I press the down button, the cube closest under gets destroyed. Is there a way to destroy a game object if you have the coordinates? (btw, I’m working js). Thank you. -Nelis

You don’t need to use colliders for your simple application. Just a 2d array.

Add a reference to each object into the array when it is created.

var theGrid : GameObject[,];
var myTransform : Transform;
var myX : int;
var myY : int;

//in awake
theGrid = new GameObject[32,32];

//in the movement function
myX = Mathf.Round(myTransform.position.x);
myY = Mathf.FloorToInt(myTransform.position.y);

//in the dig function
if (theGrid[myX,myY-1])
    {
    Destroy(theGrid[myX,myY-1],0.1);
    }

BTW are you making a Lode Runner derivative? That was one of my favorite ancient PC games.

Search the game object which have following coordinates n java script then destroy it

Have you tried checking the isTrigger in your box collider? You can handle this through trigger events. For example, you could set a cube that is moving to layer 8 by using a bool to find out if it’s moving. Then:

if( moving )
{

gameObject.layer = 8
}

Then you can check if that collider enters or stays on a trigger. OnTriggerEnter or OnTriggerStay. Here is an example with OnTriggerEnter.

 function OnTriggerEnter( other : Collider )
    {
    
    if( other.gameObject.layer == 8 )
    {
    
    Destroy( gameObject );
    }

Hope that helps.