Advertisement
natmaxex

Text Color Code

Nov 1st, 2022 (edited)
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | Software | 0 0
  1. public void ColorLoop() {
  2.     TMP_Text scriptWordCash;
  3.     bool quotationDetected = false;
  4.     bool comment_V1_Detected = false;
  5.     bool comment_V2_Detected = false;
  6.  
  7.     foreach (GameObject _scriptTextObj in scriptTextObj)
  8.     {
  9.         scriptWordCash = _scriptTextObj.GetComponent<TMP_Text>();
  10.  
  11.         //-- quoation start --//
  12.         if (scriptWordCash.text == "\"")
  13.         {
  14.             quotationDetected = !quotationDetected;
  15.         }
  16.  
  17.         //-- quoation End --//
  18.         if (quotationDetected)
  19.         {
  20.             ColorScript(scriptWordCash, Color.yellow);
  21.         }
  22.  
  23.         //-- comment v1 Start --//
  24.         if (scriptWordCash.text == "//")
  25.         {
  26.             comment_V1_Detected = true;
  27.         }
  28.  
  29.         //-- comment v1 End --//
  30.         if (comment_V1_Detected )
  31.         {
  32.             ColorScript(scriptWordCash, Color.green);
  33.             if (scriptWordCash.text == "\n" || !comment_V2_Detected)
  34.             {
  35.                 comment_V1_Detected = false;
  36.             }
  37.         }
  38.  
  39.         //-- comment v2 Start --//
  40.         if (scriptWordCash.text == "/*")
  41.         {
  42.             comment_V2_Detected = true;
  43.         }
  44.  
  45.         //-- comment v2 End --//
  46.         if (comment_V2_Detected)
  47.         {
  48.             ColorScript(scriptWordCash, Color.green);
  49.             if (scriptWordCash.text == "*/")
  50.             {
  51.                 comment_V2_Detected = false;
  52.             }
  53.         }
  54.        
  55.         // Give Text a random color
  56.         if (!quotationDetected &&
  57.             !comment_V1_Detected &&
  58.             !comment_V2_Detected)
  59.         {
  60.             ColorScript(scriptWordCash, new Color(Random.value, Random.value, Random.value, 1));
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement