Feast or Famine with GuiText

I can’t believe I’m asking this. Go ahead, yell at me, tell me to search. I deserve it, because this is a hella simple question that for some reason I haven’t quite found the answer to.

You see an item. You pick it up. When you pick it up, I’d just like a brief little text to appear that says what you picked up, then disappear shortly after. “Congrats, you just found dirty underwear!” or something like that.

So at first I couldn’t get anything to appear at all. After a little bit of tweaking, I got the text to appear, but it’s there right from the start. So now the screen is littered with text boxes. Sorry, really. Here’s the code. Thanks for helping, and God bless.

var pickuphardtacktext = true;
var textArea = new Rect(0,0,Screen.width, Screen.height);
var pickuphardtack : GUIText;

function Update () {

}

function OnTriggerEnter (col : Collider) {
pickuphardtacktext = true;
if (col.gameObject.tag == "Player") {

Inventory.inventoryArray[1]++;


Destroy(this.gameObject);

}

}

function OnGUI()
{
if(pickuphardtacktext)

{
GUI.Label(textArea, "You found a Hard Tack Cracker!");
}


}

Also, yep, I see that I have both a GuiText object appear, as well as text right in the script. Not wanting both, I just throwing stuff at the problem to see what would stick.

I’ve tackled something similar by having a GUI script (attached to an empty game object with a load of other ‘manager’ scripts) with the following code in it’s OnGui method:

if(!String.IsNullOrEmpty(GUIMessageCenter)){
    GUI.Box(Rect(Screen.width / 2 - 200, Screen.height / 2, 400, 25), GUIMessageCenter);
}

GUIMessageCenter being a public variable that I set from other scripts via a coroutine (to allow the message to remain for x seconds):

GUIScript.GUIIMessageCenter = "Matter hose not connected";
yield WaitForSeconds(2);
GUIMessageCenter = "";

This is pretty hacky, and could be much better written, but hopefully it gives you some ideas