Advertisement
drakon-firestone

Untitled

Mar 13th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public static string RED_TAG => "Red";
  2. public static string BLUE_TAG => "Blue";
  3. public static string GREEN_TAG => "Green";
  4.  
  5. [SerializeField] private Renderer rend;
  6.  
  7. [SerializeField] private Slider redSlider;
  8. [SerializeField] private Slider greenSlider;
  9. [SerializeField] private Slider blueSlider;
  10.  
  11. [SerializeField] private TMP_Text redSliderText;
  12. [SerializeField] private TMP_Text greenSliderText;
  13. [SerializeField] private TMP_Text blueSliderText;
  14.  
  15. [SerializeField] private Color col;
  16.  
  17. public static Color IntToColor(int red, int green, int blue)
  18. {
  19. float r = (float)red / 255;
  20. float g = (float)green / 255;
  21. float b = (float)blue / 255;
  22. Color col = new Color(r, g, b);
  23. return col;
  24. }
  25.  
  26. void SetCarColor(int red, int green, int blue)
  27. {
  28. Color col = IntToColor(red, green, blue);
  29. rend.material.color = col;
  30. PlayerPrefs.SetInt("Red", red);
  31. PlayerPrefs.SetInt("Green", green);
  32. PlayerPrefs.SetInt("Blue", blue);
  33. }
  34.  
  35. public static Color GetCarColor()
  36. {
  37. return IntToColor(
  38. PlayerPrefs.GetInt("Red"),
  39. PlayerPrefs.GetInt("Green"),
  40. PlayerPrefs.GetInt("Blue")
  41. );
  42. }
  43.  
  44.  
  45. private void Start()
  46. {
  47. rend.material.color = GetCarColor();
  48.  
  49. redSlider.value = (int)(col.r * 255f);
  50. greenSlider.value = (int)(col.g * 255f);
  51. blueSlider.value = (int)(col.b * 255f);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement