using UnityEngine; using UnityEngine.UI; public class MyUIElement : MonoBehaviour { public Image myImage; void Start() { myImage.color = Random.ColorHSV(); } }
using UnityEngine; public class MyGameObject : MonoBehaviour { void Start() { Renderer myRenderer = GetComponentIn this example, we have a game object with a Renderer component that we want to set to a random color. We use the Random.ColorHSV() function with specific ranges for hue (0-1), saturation (0.5-1), and value (0.5-1) to generate a random color and set it as the material color of the Renderer component. Package Library: UnityEngine(); myRenderer.material.color = Random.ColorHSV(0f, 1f, 0.5f, 1f, 0.5f, 1f); } }