MessageDisplayer

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
Line 1: Line 1:
Author: Jon (Aarku)
+
Author: Jonathan Czeck (aarku)
 
----
 
----
 
Use this script on a guiText object to have status messages
 
Use this script on a guiText object to have status messages

Revision as of 06:37, 1 December 2005

Author: Jonathan Czeck (aarku)


Use this script on a guiText object to have status messages Just call messageDisplayerObject.DisplayMessage("hello") and you'll get a line of self disappearing messages.


using UnityEngine;
using System.Collections;

// Use this script on a guiText object to have status messages
// Just call messageDisplayerObject.DisplayMessage("hello") and you'll
// get a line of self disappearing messages.

public class MessageDisplayer : MonoBehaviour
{
	ArrayList messages = new ArrayList();
	
	public void DisplayMessage(string message)
	{
		messages.Add(message);
		UpdateDisplay();
		Invoke("DeleteOldestMessage", 5F);
	}
	
	void DeleteOldestMessage()
	{
		messages.RemoveAt(0);
		UpdateDisplay();
	}
	
	void UpdateDisplay()
	{
		string formattedMessages = "";
		
		foreach (string message in messages)
		{
			formattedMessages += message + "\n";
		}
		
		guiText.text = formattedMessages;
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox