Just been using the MessageList script
http://www.unifycommunity.com/wiki/index.php?title=MessageList
on the Wiki and although I have it working and am calling the routine ok, I can’t pass a defined string to it.
In my Controller script I assemble my string from two names i.e JOE and BLOGGS. I then want to pass to the MessageList script the String:
var winner : String=“JOE”+“BLOGGS”
var passString : String="1st place is "+winner
// send winner String to script
The MessageList script just shows “1st place is”. How do I pass the whole ‘winner’ String? I’ve tried making it Static but no luck.
So, if I am reading this correctly, AddMessage adds a message to the starting position of 20,20,0 (top right alignment) and never adjusts that number. Would this not put every message added in the bottom right corner? Would these messages not overlap?
Sadly, I got to tinkering with a simple messaging system and came up with this:
class Message{
var text : String;
var start : float;
function Message(message){
text=message;
start=Time.time;
}
}
private var messages=new Array();
var duration = 2.0;
function Start () {
if(!guiText)
gameObject.AddComponent(GUIText);
guiText.anchor=TextAnchor.LowerLeft;
transform.position=Vector3(0,0,0);
AddMessage("TEST");
while(true){
if(messages.length > 0){
if(Time.time > messages[0].start + duration){
for(var i=0; i < messages.length; i++){
if(Time.time > messages[i].start + duration){
messages.RemoveAt(i);
i--;
}
}
BuildText();
}
}
yield;
}
}
function AddMessage(message){
if(message=="") return;
var newMessage=new Message(message as String);
messages.Add(newMessage);
BuildText();
}
function Update(){
var move=Vector3(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"),0);
if(move.magnitude > 0.0) AddMessage("" + move);
}
function BuildText(){
var s="";
for(var i=0; i < messages.length; i++){
s=s + messages[i].text;
if(i < messages.length-1) s=s+"\n";
}
guiText.text=s;
}
Of course remove the Update and the AddMessage(“Test”) lines and all you would have to do is:
var msger = GameObject.FindObjectOfType(MessageList);
msger.AddMessage("My Message to add");
To add messages to it. You can even control how long they stay up. This is an incredible debugging tool just in case you wanted to know.
Thanks BMB. The original message script ‘stacked’ the messages, so the former message would move up, vidiprinter-style, to be replaced by the newest message. It works nice with the fading, but I’m still stuck on how to get a String to it from another script. I’ll give yours a go, though it doesn’t do any snazzy effects I like the idea of its debugging uses.