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

Color.r

建议更改

成功!

感谢您帮助我们改进 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提供的每个建议更改,并在适当时进行更新。

关闭

提交失败

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

关闭

取消

public float r;

描述

颜色的红色分量。

值范围为 0 到 1。

//Attach this script to a GameObject with a Renderer attached to it
//Use the sliders in Play Mode to change the Color of the GameObject's Material

using UnityEngine;

public class Example : MonoBehaviour { Renderer m_Renderer; //Set the Color to white to start off public Color color = Color.white;

void Start() { //Fetch the Renderer of the GameObject m_Renderer = GetComponent<Renderer>(); }

private void OnGUI() { //Sliders for the red, green and blue components of the Color color.r = GUI.HorizontalSlider(new Rect(0, 00, 100, 30), color.r, 0, 1); color.g = GUI.HorizontalSlider(new Rect(0, 40, 100, 30), color.g, 0, 1); color.b = GUI.HorizontalSlider(new Rect(0, 80, 100, 30), color.b, 0, 1);

//Set the Color of the GameObject's Material to the new Color m_Renderer.material.color = color; } }