LoginSignup
34
27

More than 5 years have passed since last update.

[Unity] Debug.Log で出力する文字の色を変えよう

Last updated at Posted at 2014-12-21

Unity の Debug.Log って見づらくないですか?
どうにかこうにかできないかなと思い調べてたら色付けできるみたいですねこれ!
http://docs.unity3d.com/ScriptReference/Debug.Log.html

ってことでそのメモです.

1.png

Debug.Log で出力する文字の色を変える

文字列をタグで囲うと, その情報が反映された状態で
表示されるみたいです.

Debug.Log ("<color=red>Hello, world!</color>");

Unity の Console パネルに赤く Hello, world! と表示されるのが
わかるかと思います.

1.png

GUI の Label とかも同じ方法でいけるみたい

下記のコードを書くと

void OnGUI() {
    GUI.Label (new Rect(10, 10, 100, 100), "<color=red>Hello, world!</color>");
}

こんな感じで表示されます!

2.png

活用例

数値が一定以上にいったらコンソールの色を変えるとかすると
便利かもなぁなんて思いました.

if (this.num < 10) {
    Debug.Log (this.num);
} else {
    Debug.Log ("<color=red>" + this.num + "</color>");
}
34
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
27