I have 2 objects, and i want a code to tell me if a object is seeing another object
tnx.
I have 2 objects, and i want a code to tell me if a object is seeing another object
tnx.
simplest way (not perfect though, as it checks only if the center of the object has a direct line of sight with other object) is to use a linecast.
var other : Transform;
function Update() {
var hit : RaycastHit;
if (LineCast(transform.position, other.position, hit)) {
if (hit.transform == other) {
Debug.Log("I see you!");
}
}
}