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; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961