- Home /
MessageBox Panel (How to add resizable Text container?)
Hello, For now I have simple MessageBox container to display game messages (for example, killed monster etc.).
My hierarchy is:
1)Panel
1a)Panel (Mask + Scroll Rect)
1ab)Panel (Vertical Layout Group + Content Size Filter + LogConsole Script)
1b)Scrollbar
LogConsole Script:
public class LogConsole : MonoBehaviour {
public GameObject Line;
List<GameObject> Messages;
int LineCount = 0;
void Start () {
Messages = new List<GameObject>();
}
public void LogMessage(string message)
{
GameObject line = (GameObject)Instantiate(Line);
line.transform.SetParent(this.transform);
line.name = "Message" + LineCount;
line.GetComponent<Text>().text = System.DateTime.Now.ToString() + ": " + message;
Messages.Add(line);
if(LineCount >= 30){
Destroy(Messages[0]);
Messages.RemoveAt(0);
}
LineCount++;
}
}
Everything works great, but I wonder, how I can make that Text container to be sized automatically? cus Small messages have huge ugly spaces, and big messages do not wrap. look screen: http://screenshooter.net/102644289/omykrny
Comment
Your answer
