Version: 2019.2
public Color color ;

Description

Base color of the Graphic.

The builtin UI Components use this as their vertex color. Use this to fetch or change the Color of visual UI elements, such as an Image.

//Place this script on a GameObject with a Graphic component attached e.g. a visual UI element (Image).

using UnityEngine; using UnityEngine.UI;

public class Example : MonoBehaviour { Graphic m_Graphic; Color m_MyColor;

void Start() { //Fetch the Graphic from the GameObject m_Graphic = GetComponent<Graphic>(); //Create a new Color that starts as red m_MyColor = Color.red; //Change the Graphic Color to the new Color m_Graphic.color = m_MyColor; }

// Update is called once per frame void Update() { //When the mouse button is clicked, change the Graphic Color if (Input.GetKey(KeyCode.Mouse0)) { //Change the Color over time between blue and red while the mouse button is pressed m_MyColor = Color.Lerp(Color.red, Color.blue, Mathf.PingPong(Time.time, 1)); } //Change the Graphic Color to the new Color m_Graphic.color = m_MyColor; } }