I have been trying to create an area around an object that you have to be in order to interact (click, highlight) an object.
I have messed around with Vecor3.Distance and thought I was on the right path and it never seemed to work.
If anyone can help point me in the right direction. Id appreciate it.
It would be helpful if you post what you have already tried.
if(Vector3.Distance(obj1.transform.position, obj2.transform.position) < 10)
{
//Do something while object is inside a range of 10 units
}
That code gave me an error for the unknown identifiers obj1 and obj2
Im not sure how to embed a code box like that but ive tried
var other : Transform;
if (other) {
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + .023);
}
and a couple more to that extent.
I have a highlight code for the object as well that I want to only be active if inside that certain range area.
It would be like this
var obj1 : Transform;
var obj2 : Transform;
if(Vector3.Distance(obj1.transform.position, obj2.transform.position) < 10)
{
//Do something while object is inside a range of 10 units
}
would I but that on the object or controller?
Sorry ive been trying to figure out scripting and which object should use what