public Color color ;

설명

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