MessageDisplayer

From Unify Community Wiki
Revision as of 07:14, 1 December 2005 by Aarku (Talk | contribs)

Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Description

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. TODO: Make this script more of a singleton.

Usage

Use this script on a guiText object to have status messages.

C# - MessageDisplayer.cs

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