Basically this code works. The problem is, when I clear the list, nothing show. I don’t clear the list and I get a lot of overlapping windows. I tried LastUpdate to clear, but I never see the text.
I need to clear the list after it renders the text. Thanx for any help in advance. (Unity 3.5.7)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class utlPrint : MonoBehaviour
{
private static utlPrint inst = null;
public class printInfo
{
public float x;
public float y;
public float height;
public float width;
public string buffer;
public printInfo(float x,float y,float width,float height,string buffer)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.buffer = buffer;
}
}
public List<printInfo> printList = null;
public static utlPrint Inst
{
get
{
if (inst == null)
{
Debug.Log("Instantiating utlPrint");
GameObject PRINTOBJ = new GameObject();
inst = PRINTOBJ.AddComponent<utlPrint>();
PRINTOBJ.name = "UTLPRINT";
inst.printList = new List<printInfo>();
DontDestroyOnLoad(PRINTOBJ);
}
return inst;
}
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
public void print(float x,float y,float width,float height,string buffer)
{
printList.Add(new printInfo(x,y,width,height,buffer));
}
void OnGUI()
{
if(printList==null)
return;
for(int i=0;i<printList.Count;i++)
{
var t = printList[i];
GUI.Box (new Rect (t.x,t.y,t.width,t.height), t.buffer);
}
printList.Clear();
}
}