I have a script that generates objects in the scene from a prefab, and I have a moveable cube. I want a script that gets the name of the object if the distance between the cube and the cloned object is < 0.3f.
I have this UnityScript:
var distance1 = Vector3.Distance(Food.transform.position, cube1.transform.position);
Debug.Log(distance1);
if(distance1 < 0.3f)
{
//Destroy nearest object
}
In this case I think is better to use Collision Detection as recommended by Barış Çırıka... but if you want to get it by distance I think you can do something like
this script should be attached to every object you instantiate.