版本:Unity 6 (6000.0)
语言英语
  • C#

SpriteRenderer.color

建议更改

成功!

感谢您帮助我们改善 Unity 文档的质量。虽然我们无法接受所有提交请求,但我们会阅读每位用户提供的建议更改,并在适用情况下进行更新。

关闭

提交失败

由于某种原因,系统无法提交您建议的更改。请<a>稍后再试</a>。感谢您抽空帮助我们提升 Unity 文档的质量。

关闭

取消

public 颜色 color;

说明

Sprite 图形的渲染颜色。

选定的顶点颜色变为渲染颜色,可以在像素着色器中访问。如果未选择颜色,则默认颜色为白色。

//This example outputs Sliders that control the red green and blue elements of a sprite's color
//Attach this to a GameObject and attach a SpriteRenderer component

using UnityEngine;

public class Example : MonoBehaviour { SpriteRenderer m_SpriteRenderer; //The Color to be assigned to the Renderer’s Material Color m_NewColor;

//These are the values that the Color Sliders return float m_Red, m_Blue, m_Green;

void Start() { //Fetch the SpriteRenderer from the GameObject m_SpriteRenderer = GetComponent<SpriteRenderer>(); //Set the GameObject's Color quickly to a set Color (blue) m_SpriteRenderer.color = Color.blue; }

void OnGUI() { //Use the Sliders to manipulate the RGB component of Color //Use the Label to identify the Slider GUI.Label(new Rect(0, 30, 50, 30), "Red: "); //Use the Slider to change amount of red in the Color m_Red = GUI.HorizontalSlider(new Rect(35, 25, 200, 30), m_Red, 0, 1);

//The Slider manipulates the amount of green in the GameObject GUI.Label(new Rect(0, 70, 50, 30), "Green: "); m_Green = GUI.HorizontalSlider(new Rect(35, 60, 200, 30), m_Green, 0, 1);

//This Slider decides the amount of blue in the GameObject GUI.Label(new Rect(0, 105, 50, 30), "Blue: "); m_Blue = GUI.HorizontalSlider(new Rect(35, 95, 200, 30), m_Blue, 0, 1);

//Set the Color to the values gained from the Sliders m_NewColor = new Color(m_Red, m_Green, m_Blue);

//Set the SpriteRenderer to the Color defined by the Sliders m_SpriteRenderer.color = m_NewColor; } }