unity build see logs

 using UnityEngine;  public class ConsoleToGUI : MonoBehaviour {     string myLog = "*begin log";     string filename = "";     bool doShow = true;     int kChars = 700;     void OnEnable() { Application.logMessageReceived += Log; }     void OnDisable() { Application.logMessageReceived -= Log; }     void Update() { if (Input.GetKeyDown(KeyCode.Space)) { doShow = !doShow; } }     public void Log(string logString, string stackTrace, LogType type)     {        // for onscreen...         myLog = myLog + "\n" + logString;         if (myLog.Length > kChars) { myLog = myLog.Substring(myLog.Length - kChars); }          // for the file ...         if (filename == "")         {             string d = System.Environment.GetFolderPath(                System.Environment.SpecialFolder.Desktop) + "/YOUR_LOGS";             System.IO.Directory.CreateDirectory(d);             string r = Random.Range(1000, 9999).ToString();             filename = d + "/log-" + r + ".txt";         }         try { System.IO.File.AppendAllText(filename, logString + "\n"); }         catch { }     }      void OnGUI()     {         if (!doShow) { return; }         GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,            new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));         GUI.TextArea(new Rect(10, 10, 540, 370), myLog);     } }

0
0
Awgiedawgie 440215 points

                                         using UnityEngine;          namespace DebugStuff     {         public class ConsoleToGUI : MonoBehaviour         {     //#if !UNITY_EDITOR             static string myLog = "";             private string output;             private string stack;                  void OnEnable()             {                 Application.logMessageReceived += Log;             }                  void OnDisable()             {                 Application.logMessageReceived -= Log;             }                  public void Log(string logString, string stackTrace, LogType type)             {                 output = logString;                 stack = stackTrace;                 myLog = output + "\n" + myLog;                 if (myLog.Length > 5000)                 {                     myLog = myLog.Substring(0, 4000);                 }             }                  void OnGUI()             {                 //if (!Application.isEditor) //Do not display in editor ( or you can use the UNITY_EDITOR macro to also disable the rest)                 {                     myLog = GUI.TextArea(new Rect(10, 10, Screen.width - 10, Screen.height - 10), myLog);                 }             }     //#endif         }     } 

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source