- Home /
Question by
JonathanGenesis · Apr 02, 2013 at 12:03 AM ·
distancevector3.distance
Check how far and if the object is in view and do something.
I want to make it so when the object is so far away and is in view to switch cameras and to animate then when the object is out of view of to far away to stop animation. this would be a great help here is my script so far.
it detects how far away and if the object is in view great but i need the other functionality to.
#pragma strict
var other : Transform;
var anObject : GameObject;
private var cam : Camera;
private var planes : Plane[];
function Start () {
}
function Update () {
//Detects how far away the object is
if (other) {
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + dist);
}
// Detects manually if anObject is being seen by the main camera
cam = Camera.main;
planes = GeometryUtility.CalculateFrustumPlanes(cam);
if(GeometryUtility.TestPlanesAABB(planes,anObject.collider.bounds))
Debug.Log(anObject.name + " has been detected!");
else
Debug.Log("Nothing has been detected");
}
Comment