Vector3.Angle

static function Angle (from : Vector3, to : Vector3) : float

Description

Returns the angle in degrees between from and to. This is always the smallest.

Angle between the two (ie, never more than 180 degrees).

JavaScript
    // prints "close" if the z-axis of this transform looks
// almost towards the target
var target : Transform;
function Update () {
var targetDir = target.position - transform.position;
var forward = transform.forward;
var angle = Vector3.Angle(targetDir, forward);
if (angle < 5.0)
print("close");
}