There are colors that were specified for the components by common names.

pieceColors = new Color[6] {Color.red, Color.blue, Color.yellow, Color.green, Color.cyan, Color.magenta}; 

Now when I want to get them with the command

 GetComponent<Controller>().getColor (); мне выдаётся информация вида RGBA(0.000, 1.000, 0.000, 1.000) 

How to get them in the form of a String?

Tried so

 Color colt = tempPieces[i].GetComponent<Controller>().getColor(); cvet.text = colt.ToString(); 

but it still returns issues via RGBA. Is there any way to convert names normally into English?

  • one
    Color.red is a class object, and in fact the number 0xFFFF0000 therefore without any additional code I can’t imagine how to do it. And the code can be simply made switch (color) case Color.red: return "red"... - pavel
  • @pavel Well, this is by hand. Can it be through if-else Now there are only 6 colors, and if there are 50 of them? Is there any way to automate this? - Dmitrii
  • one
    And what is this controller and getColor method? and where does pieceColors , which is not listed anywhere here, except for the beginning of the question? And doesn't Color have a Name property? ... because Color color = Color.Red; string colorName = color.Name; Debug.Log(colorName); Color color = Color.Red; string colorName = color.Name; Debug.Log(colorName); will give Red - Aleksey Shimanskyy
  • one
    And if you use not UnityEngine.Color , but System.Drawing; will there be a mistake? - Alexey Shimansky
  • one
    If you have 50 of them, then you will have to give them the names in your hands anyway, because there are no 50 predefined colors in Unity, which means you will need a structure with a name field, that’s the word. And if you talk about the current situation, you can look in the direction of reflection, even though this perversion is used in such circumstances. - justyx

0