How to get the name of an object inside a script to display in the GUI

Ok, so I’m incredibly new to this so I’m pretty sure I’m doing some obvious mistakes.

I have a object in the world tagged as OBJECT. My goal is that when I click on it with the mouse a GUI appears and shows whatever information I wrote inside a script attached to this object.

So this is the script inside the object (in the inspector I wrote for objName something else)

var objName = "default name" ;					
var objWeight = 0 ;
var objDescription = "default description" ;	

static var displayName : String ;
static var displayDescription :String ;

then I have a script that detects what is the name of the object under the mouse:

var smooth:int; // Determines how quickly object moves towards position
static var targetPosition:Vector3;		//this is the final cursor position
static var target : Collider ;
static var selectedObject : Transform;

function Update () {

		// Generate a plane that intersects the transform's position with an upwards normal
		var playerPlane = new Plane(Vector3.up, transform.position);

		// Generate a ray from the cursor position
		var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

    // Determine the point where the cursor ray intersects the plane.
    // This will be the point that the object must look towards to be looking at the mouse.
    // Raycasting to a Plane object only gives us a distance, so we'll have to take the distance,
    //   then find the point along that ray that meets that distance.  This will be the point
    //   to look at.
		var hitdist = 0.0;
    // If the ray is parallel to the plane, Raycast will return false.
		if (playerPlane.Raycast (ray, hitdist)) {
			 // Get the point along the ray that hits the calculated distance.
			var targetPoint = ray.GetPoint(hitdist);

			targetPosition = ray.GetPoint(hitdist);

			// Determine the target rotation.  This is the rotation if the transform looks at the target point.
			var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

			// Smoothly rotate towards the target point.
			transform.rotation = targetRotation;
	transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);

    var hit : RaycastHit;
    	if (Physics.Raycast (ray, hit, 100)) {

    	Debug.DrawLine (ray.origin, hit.point);			//Draws the ray

	target = hit.collider;
	selectedObject = hit.transform;

Then I use this script to help me define what happens when the object under the mouse is tagged as OBJECT and I click on it:

static var guiPlayer : Transform;
static var objProperties ;

if ( == "OBJECT" && Input.GetMouseButtonUp(0) == true){
		leftClickOnObject = true;
		guiPlayer = Mouse_Position.selectedObject;						
            objProperties = GameObject.Find(;
	if ( != "OBJECT" && Input.GetMouseButtonUp(0) == true){
		leftClickOnObject = false;

Finally I have a script for the GUI that should show the ‘static var displayName’ of the object that is under it…

if (Detect_Player_Input.leftClickOnObject == true){
	//if (Detect_Player_Input.mouseOverObject == true && mouseClick == true){
		// Make a background box
		GUI.BeginGroup (Rect (mouseX - 160, mouseY -120, 460,260), "");
		GUI.Box (Rect (0, 0, 320, 220),;

Now my problem is that writing this only gives me the displayName of the first object, after that it doesnt update anymore. Like I mentioned, I’m pretty new at this so not sure if this is the best way even to do these things…

Thanks for the help!

Thanks for the feedback. So a collider would be cheaper than using the plane?
I’m also going to try to explain what the problem is exactly since I feel I wasnt clear enough.