こんにちは、今日はUnityでConsoleウィンドウにログを表示する方法についてまとめていきます。
Table of Contents
確認環境
Unity 2018.4.15f1
ログの出力
ログの出力にはUnityEngine.Debugクラスに定義されている関数を使用します。
以下のコードでConsoleウィンドウにログが出力されます。
ログ出力

Debug.Log("Log Test");
アサーション出力

Debug.LogAssertion("LogAssertion Test");
エラーメッセージ出力

Debug.LogError("LogError Test");
警告メッセージ出力

Debug.LogWarning("LogWarning Test");
ログをクリック時に対応するオブジェクトをハイライト表示する
それぞれのログ出力関数には第二引数にObjectを渡すことができ、Consoleウィンドウでそのログをクリックした際にHierarchyウィンドウでオブジェクトがハイライトされます。
ログ出力の文字を装飾する
文字列の色やサイズを指定できるリッチテキストがログ出力でも使用できます。
以下の例ではLog Testと表示される内のLogの部分が赤色で表示されます。
Debug.Log("<color=red>Log</color> Test");

使用できるタグ等の詳細はUnity公式マニュアルの以下ページに記載されています。