destroy gameobject by distance value

Hello everybody
I want a help in unity2d JS script
I have a script that generate objects in the sence from a prefab
and I have a movable cube
I want a script That get the name of the object if the
distance between the cube and the cloned object is < 0.3f

Any suggestions ?

Thanks

I don’t know javascript so you might have to do a little syntax cleanup here…

var DistanceBetweenObjects = (object1.transform.position - object2.transform.position).magnitude;

if (DistanceBetweenObjects < 0.3f)
    var ObjectsName = object2.name;

You’ll have to loop through the objects and check the distance to each one