DEV Community

Hiromichi Yamada
Hiromichi Yamada

Posted on • Updated on

Unity Debug Print

using UnityEngine;
using System.Text;

#region Debug Print

[SerializeField]
private Text DebugText; // for UnityEngine.UI.Text

private void PrintDebug( string s, bool showTime = true)
{
    if(DebugText != null)
    {
        StringBuilder sb = new StringBuilder();
        if (showTime)
        {
            sb.Append(System.DateTime.Now.ToString("[HH:mm:ss] "));
        }
        sb.AppendLine(s);
        sb.AppendLine(DebugText.text);

        DebugText.text = sb.ToString();
    }
}


#endregion / Debug Print
Enter fullscreen mode Exit fullscreen mode

Top comments (0)