unity3d - Destroy Gameobject according to distance value -


i have script generates objects in scene prefab, , have moveable cube. want script gets name of object if distance between cube , cloned object < 0.3f.

i have unityscript:

var distance1 = vector3.distance(food.transform.position, cube1.transform.position); debug.log(distance1);  if(distance1 < 0.3f) {    //destroy nearest object  } 

in case think better use collision detection recommended barış Çırıka... if want distance think can like

var mycube =  gameobject.findgameobjectswithtag("mycube"); lateupdate(){ var distance = vector3.distance(this.gameobject.transform.position, mycube.transform.position); if(distance < 0.3f) { destroy(this.gameobject); } } 

this script should attached every object instantiate.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -