[Unity]Print Log on Screen
Keywords: Unity, Basic Usage
From scratch
C# Script (Thanks for Jaakko Saaristo
):
using System.Collections;
using UnityEngine;
public class ScreenLogger : MonoBehaviour {
private string log;
private const int MAXCHARS = 10000;
private Queue myLogQueue = new Queue();
void Start() {
Debug.Log("Screen logger started");
}
void OnEnable() {
Application.logMessageReceived += HandleLog;
}
void OnDisable() {
Application.logMessageReceived -= HandleLog;
}
void HandleLog(string logString, string stackTrace, LogType type) {
myLogQueue.Enqueue("\n [" + type + "] : " + logString);
if (type == LogType.Exception)
myLogQueue.Enqueue("\n" + stackTrace);
}
void Update() {
while (myLogQueue.Count > 0)
log = myLogQueue.Dequeue() + log;
if (log.Length > MAXCHARS)
log = log.Substring(0, MAXCHARS);
}
void OnGUI() {
GUILayout.Label(log);
}
}
Reference:
Print debug.log to screen? C#
https://answers.unity.com/questions/1020051/print-debuglog-to-screen-c.html
Using plugin
A simple and fully customizable screen logger. Just put it on a scene and you will see on screen output for each call to Debug.Log/LogWarning/LogError.
https://assetstore.unity.com/packages/tools/gui/screen-logger-49114
I love you not for whom you are, but who i am when i'm by your side. ― Gabriel García Márquez