0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity コンソール画面にコメントを出す方法、Debug.Log関数の使い方

Last updated at Posted at 2021-06-16

##0.0 はじめに
Debug.Log関数を使用することでコンソール画面にコメントを出力することができます。
スクリプトからのコメント出力や実行中の変数の中身が確認できます。
不具合を取り除くためにデバッグのログ(記録)を取り出すことができるのでとても便利です。
Debugはいろいろな使い方がありますがここでは最もシンプルな初心者向けの使い方を紹介します。

##1.0 Debug.Log関数の使い方
####1.1 コメントの表示

Test.cs
Debug.Log("Hello World"); // Hello Worldをコンソールに表示

####1.2 変数の中身の表示

Test.cs
int num = 123;
Debug.Log(num); // numの値をコンソール画面に表示

####1.3 いろいろな表示

Test.cs
int num = 1234;
Debug.Log("numの値は" + num + "です"); // numの値は1234です とコンソール画面に表示されます

####1.4 いろいろな表示2
引数に$を頭に入れると{}で変数をそのまま使えます。
(下のスクリプトは1.3と同じ結果になります。)

Test.cs
int num = 1234;
Debug.Log($"numの値は{num}です"); // numの値は1234です とコンソール画面に表示されます

##2.0 コンソール画面での表示
コンソール画面では1行目にログの内容、2行目以降にログが呼ばれた場所が示されています。
image.png
👍ポイント
3行目ではTestクラスのStart()関数で呼ばれていること、()内ではTest.csの10行目から呼び出されていることが示されています。

##3.0 おまけ
リッチテキストで色やフォントサイズを変更できます。

Test.cs
int num = 1234;
Debug.Log("<color=#ff0000ff>numの値は</color>" + num + "<size=20>です</size>"); // とコンソール画面に表示されます

image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?