- Home /
checking the objects close to me
i need to check objects close to me tagged = "RA13" i do not have an idea how can i do this.
if a tagged="RA13" object close to me , i will destroy it.
edit : if this impossible , please use js
Answer by AtomicMarine · Feb 14, 2011 at 07:28 PM
var you : Transform; var thePlayer : Transform; var distanceToDestroy : float = 1.0;
function Update(){
var dist = Vector3.Distance(thePlayer.position,you.position);
if (dist > distanceToDestroy){
var object = gameObject.FindWithTag("theObjectYouWantToKill");
Destroy(object);
}
}
this code will check the distance between two transforms, the Player and your object, if it is less then a certain number it will destroy the tagged object, you just need to initialize the object as transform being used on your script, there are a few ways to change this based on tags if you need more help comment me.
I think you just copied and pasted something that worked for you, that functions somewhat similarly to what Eren Aydn asked for. I think you can answer significantly better with just a little more effort.
Your answer
Follow this Question
Related Questions
Opening and closing drawers with start and end points 1 Answer
How to check if specific objects touch 0 Answers
Check if two objects have the same position. 2 Answers
Checking position 2 Answers
creating custom occlusion culling? 2 Answers