Talking to multiple NPC's

I’m planning on having multiple characters the player could talk to, this is I’m planning on having multiple NPC scripts, each with different dialogue. Whenever the player is within range in front of an NPC, and the Player and NPC are facing eachother, a dialogue box will pop up with the push of a button. However, I want this only to occur if the player is currently looking at the front of the NPC.

The second script (Player script), uses a raycast to detect the NPC object, but it doesn’t care from which side the NPC is being looked at. The reason I made this script was so that the dialogue box would only pop up when the two characters (player and NPC) are looking at each other. I was trying to reference the NPC GUI script in the Player’s script, but Unity won’t let me reference a boolean…

I feel like I’m missing something and going about this the wrong way. I’m open to alternate suggestions as to how to go about this. I’m still pretty new to scripting and I’m still trying to get a hang of it…

NPC script:

var target : Transform;
var guiEnabled : boolean;
var visionRange : float;   //DISTANCE
var visionAngle : float;   //ANGLE

//////////////////////////////////////////////////////////////
function OnGUI() {
if (guiEnabled) {
GUI.skin.box.wordWrap = true;  
GUI.color.a = 1;
GUI.Box(Rect(10,Screen.height/2+115,Screen.width-15,Screen.height/2-120),"blahblah");
  }
}
//////////////////////////////////////////////////////////////



function Update() {
	
	//DISTANCE
	var dist : float = Vector3.Distance(target.position, transform.position);

	
	//Vector3.Angle Example
	var targetDir = target.position - transform.position;
    var forward = transform.forward;
    var angle = Vector3.Angle(targetDir, forward);
	///////////////////////
	
	        if(angle < visionAngle && dist <= visionRange){
            //print ("The other transform is behind me!");
            guiEnabled = true;	
        }
        
        else{
        	//print ("Nothin'!");
        	guiEnabled = false;	
        }
    
    }

Player script:

var target : Transform;
//var guiEnabled : boolean;
var visionRange : float;   //DISTANCE
var visionAngle : float;   //ANGLE



function Update() {
	
	//DISTANCE
	var dist : float = Vector3.Distance(target.position, transform.position);

	
	//Vector3.Angle Example
	var targetDir = target.position - transform.position;
    var forward = transform.forward;
    var angle = Vector3.Angle(targetDir, forward);
	///////////////////////
	
	        if(angle < visionAngle && dist <= visionRange){
            print ("THERE!");
            //guiEnabled = true;	
        }
        
        else{
        	print ("Nothin'!");
        	//guiEnabled = false;	
        }
    
    }

Thanks in advance!

why not have your player and npc both have raycast, and only if both are within the ray then you pop up your dialog?

To access a Boolean in another object:

target.GetComponent.<NPC>().guiEnabled

(Assuming target is a GameObject or a Component subclass and NPC is the class of the script)

I don’t really understand how that helps, because I don’t really understand what you are trying to do, but that is how you access variables in components of other objects,