using UnityEngine; public class ChangeColor : MonoBehaviour { public Material mat; public Color newColor; void Start() { mat.color = newColor; } }
using UnityEngine; public class RandomColor : MonoBehaviour { void Start() { Color randomColor = new Color(Random.value, Random.value, Random.value, 1f); GetComponentIn this example, we use the `Random` class to generate random RGB values and assign them to a `Color` object. We then apply the generated color to a material object through the `color` property. Package library: UnityEngine.().material.color = randomColor; } }