How to check in which direction an object is facing?

Hi,

I want to be able to check whether an object is looking at another object. Any ideas on how to do this would be great.

Thanks

Use something like below, where on the global script the var rayCastHitName holds the result of the ray cast.

private var globalVars : GameObject;	// Referance to the GameObject with the GlobalVars on
private var hit : RaycastHit;

function Awake(){

	globalVars = GameObject.Find("Global Vars");	// Find the gameObject with the GlobalVars.js attached to it
}

function Update(){

if (Physics.Raycast (transform.position,transform.forward,hit, 10)) {
       globalVars.GetComponent(GlobalVars).rayCastHitTag = hit.collider.gameObject.tag;
    }
}

Use a ray cast Unity - Scripting API: Physics.Raycast then check to see if it hits the player

if(hit.collider.gameObject.tag == "Player"){