Script that changes the color of a material on a game object to a random color when the player presses the “C” key.

using UnityEngine;

public class RandomColorChange : MonoBehaviour
{
    private Material material;

    private void Start()
    {
        material = GetComponent<Renderer>().material;
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            material.color = Random.ColorHSV();
        }
    }
}

Related Posts

Leave a Reply