How to make text pop up for a few seconds?

Like in Call of Duty, when you get a kill, your XP pops up for a second and then disappears. How would this be done in Unity. If you could give me and example in a script, preferably C#, but JavaScript is fine too, that’d be great. Thanks in advanced.

In some function:

if (kill) {
	StartCoroutine(ShowMessage("Abc", 2));
}

Along with:

IEnumerator ShowMessage (string message, float delay) {
	guiText.text = message;
	guiText.enabled = true;
	yield return new WaitForSeconds(delay);
	guiText.enabled = false;
}

public void MouseIsIn(){
this.transform.localScale=new Vector3 (1.2f,1.2f,1f);
}

	public void MouseIsOut(){
		this.transform.localScale=new Vector3 (1f,1f,1f);
	}

and use it with event trigger that sits on text @TheMagzuz

Here’s a quick little script for what you’re looking for.

using UnityEngine;
using System.Collections;
using System;

class ShowTextForAFewSeconds : MonoBehavior
{
	/*
	* Start Copying Here
	*/
	
	private bool showText = false, someRandomCondition = true;
	private float currentTime = 0.0f, executedTime = 0.0f, timeToWait = 5.0f;
	
	void OnMouseDown()
	{
		executedTime = Time.time;
	}
	
	void Update()
	{
		currentTime = Time.time;
		if(someRandomCondition)
			showText = true;
		else
			showText = false;
		
		if(executedTime !== 0.0f)
		{
			if(currentTime - executedTime > timeToWait)
			{
				executedTime = 0.0f;
				someRandomCondition = false;
			}
		}
	}
	
	void OnGUI()
	{
		if(showText)
			GUI.Label(new Rect(0, 0, 100, 100), "Some Random Text");
	}
	
	/*
	* Stop Copying
	*/
}