Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class LoggingTextUpdate : MonoBehaviour
{
public Text label;
public static string _msg = ">";
public static string _oldmsg = "";
public static string _error_msg = ">";
public static string _old_error_msg = ">";
public float updateInterval = 5.0F;
private float timeleft;
void Start()
{
timeleft = updateInterval;
label.text = "";
}
void Update()
{
if (_error_msg != _old_error_msg) {
label.color = Color.red;
label.text = _error_msg;
_old_error_msg = _error_msg;
timeleft = updateInterval;
}
else if (_oldmsg != _msg) {
label.color = Color.grey;
label.text = _msg;
_oldmsg = _msg;
timeleft = updateInterval;
}
timeleft -= Time.deltaTime;
if (timeleft <= 0.0) {
timeleft = updateInterval;
_msg = "";
_oldmsg = "";
_old_error_msg = "";
_error_msg = "";
label.text = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.