Version: 2017.3
public Color color ;

描述

此 Graphic 的基色。

内置 UI 组件使用此颜色作为其顶点颜色。使用此属性可获取或更改视觉 UI 元素(如图像)的颜色。

//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; } }