Skip to content

Instantly share code, notes, and snippets.

@josephwilk
Created April 23, 2018 09:24
Show Gist options
  • Save josephwilk/728ea208d6e190da07a91fd0df72a435 to your computer and use it in GitHub Desktop.
Save josephwilk/728ea208d6e190da07a91fd0df72a435 to your computer and use it in GitHub Desktop.
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