when First Person camera moves to particular object, display a message

I am new to unity but trying to learn it. I am trying to display a message on the screen when first person camera moves to particular object. Can anybody help me please?

Break it down, you need to achieve 2 things :

1/ What is in front of the camera?
2/ display a message based on 1

for 1, I suggest a raycast : Unity - Scripting API: Physics.Raycast

for 2, I suggest a switch/case, eg :

function ShowMessage( theValue : int ) 
{
	switch( theValue )
	{
		case 0 :
			// show message for object 0
		break;
		
		case 1 :
			// show message for object 1
		break;
		
		case 2 :
			// show message for object 2
		break;
	}
}

here is some example script :

function CheckForObject() 
{	
	var centerScreen : Vector3 = new Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 );
	var ray = Camera.main.ScreenPointToRay( centerScreen );
	var hit : RaycastHit;
	var distance : float = 2.5;
	
	if ( Physics.Raycast( ray, hit, distance ) )
	{
		Debug.Log( "Raycast hit : " + hit.collider.gameObject.name );
		ShowMessage( hit.collider.gameObject.name );
	}
}


function ShowMessage( theName : String ) 
{
	switch( theName )
	{
		case "Door1" :
			// show message for object Door1
		break;
		
		case "Door2" :
			// show message for object Door2
		break;
		
		case "Signpost1" :
			// show message for object Signpost1
		break;
	}
}

You want to use raycasting.

var hit : RaycastHit;
var showMessage = false;

function Update () 
{
	if (Physics.Raycast(transform.position, transform.forward, hit, Mathf.Infinity))
	{
		if (hit.collider.transform.name == "Objects Name Here")
		{
			showMessage = true;
		}
	}
	
	if (showMessage)
		Debug.Log("Show Message");
}