GUI Text Showing Gameobjects information

hi all, i need to build a game that will be informative , so that when i get closer to some game objects , it will show information about these objects that will be displayed on a GUI Text . How to do that ? any hints?

   if there is some scripts i will appreciate that.

Psuedo:

Give objects you want with info a tag as info.

Make an array of objects with that tag by doing FindObjectsWithTag("info"); (I believe).

Have a toggle key (I'd do toggle key with the way that I'm saying), for this check input API, and if player pushes the key, check distances between that person and the gameobjects with the tag, and if the player is within distance, than show the GUI txt, or you can have a child of the object, and enable it that shows a material with the info above it...

Sorry, this is kinda messed up, I was going to delete it but figured you might find some use out of it, so I'll just post it, see what you can get from it.

Hope it helps though!

While Justin's idea would technically work, it would not be what I'd consider a good method.

Create a script called ObjectInformation. Have it look something like this:

var information : String = "";

Add this script to any object you want to have abstract information associated with it. Then in your player script, add this script:

function OnGUI() {

    var hit : RaycastHit;

    if (Physics.Raycast (transform.position, transform.forward, hit, 100.0)) { // The last parameter is the distance you want to test for
        var info : String = "size: ";
        info += hit.transform.localScale;
        info += "
position: ";
        info += hit.transform.position;
        info += "
rotation: ";
        info += hit.transform.rotation;
        info += "
abstract info: ";
        var objInfo : ObjectInformation = hit.transform.gameObject.GetComponent(ObjectInformation);
        if (objInfo) {
            info += objInfo.information;
        }

        else {
            info += "null";
        }

        GUILayout.Label("info");
    }

    else
        GUILayout.Label("No object found.");
}

Please don't be just another dumb copy and paste dev with no talent, respect, intelligence, or pride. Read and try to understand the code also.

Sorry i have been away from unity game engine but now i am back developing some games
i have tried your script and it looks straight forward and simple ,
the usage of the ray cast is a smart idea from you .

Thanks man