- Home /
debug.log with color (variable)????????
After looking at this reference page: http://docs.unity3d.com/ScriptReference/Debug.Log.html
I have this variable at the top of my code
private Color[] color_debug_log = new Color[]{ Color.red,
Color.green,
Color.blue,
Color.magenta};
when I debug log like this however
Debug.Log ("<color=color_debug_log[1]>Player " + 1 + " joined the game");
it gives me default color, instead of green. Is it not possible to use color variable in these cases? the fact that the tag must be inside string is something I can see being a problem when trying to access a variable.
You can read this document: http://docs.unity3d.com/$$anonymous$$anual/StyledText.html
It includes all styles which could be used in Debug.Log()
Answer by Eric5h5 · Jan 22, 2015 at 12:54 AM
You can use a variable, but naturally it has to be outside the string; otherwise Unity has no idea it's a variable. Also the variable would have to be a string, not a Color, because you're outputting strings where the color is parsed from the string.
Thanks mate! That worked! I stored an array of strings ins$$anonymous$$d of colours, and then i concatenated it in to the colour's position in string. cheers :D
Answer by ismakefire · Jun 08, 2017 at 03:50 PM
A code sample for easy reference.
Color color = color_debug_log[1];
string message = "Player " + 1 + " joined the game";
Debug.Log (string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(color.r * 255f), (byte)(color.g * 255f), (byte)(color.b * 255f), message));
Answer by Seyed_Morteza_Kamaly · Oct 18, 2019 at 10:31 AM
KamaliDebug
https://github.com/smkplus/KamaliDebug
Easy way to Debug Colorful Texts in Unity Console
Variables
Syntax
(Text or Emoji):Color:TextStyle;
Font Color
DebugX.Log("Hello world:green;");
Font Style
DebugX.Log("Hello:b; World:i;");
Emoji
DebugX.Log("love:red:b; love:red:b; love:red:b;");
Complex
DebugX.Log("Hello:yellow:b; world:red:b;");
Answer by bart42 · Jun 21, 2021 at 11:11 AM
You can do
print($"<color=#00FF00>All files processed...</color>");
Answer by onetimepad · Apr 23 at 12:39 PM
public static string Colorize(string text, string color, bool bold){
return
"<color="+color+">"+
(bold?"<b>":"")+
text+
(bold?"</b>":"")+
"</color>";
}