zero3growlithe

Rainbow text for unity Debug.Log

Jul 2nd, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. public static string ToRainbow (this string sourceText)
  2. {
  3.     string finalText = "";
  4.  
  5.     foreach (char letter in sourceText)
  6.     {
  7.         Color randomColor = new Color(
  8.             Random.Range(0.0f, 1.0f),
  9.             Random.Range(0.0f, 1.0f),
  10.             Random.Range(0.0f, 1.0f)
  11.         );
  12.  
  13.         if (letter == ' '){
  14.             finalText += letter;
  15.         }
  16.         else
  17.         {
  18.             finalText += string.Format("<color=#{0}>{1}</color>", randomColor.ToHex(), letter);
  19.         }
  20.     }
  21.  
  22.     return finalText;
  23. }
  24.  
  25. public static string ToHex (this Color32 sourceColor)
  26. {
  27.     string hex = sourceColor.r.ToString("X2") + sourceColor.g.ToString("X2") + sourceColor.b.ToString("X2");
  28.  
  29.     return hex;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment