您如何在Unity C#中使用Color32?我试图找出如何,但它似乎不起作用

发布于 2025-02-07 06:29:19 字数 1488 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒绊 2025-02-14 06:29:19

color 对于组件值,使用0到1的范围。

您可以使用构造函数构造颜色。

var darkRed = new Color(0.55f, 0, 0, 1f);

我使用您的问题中的代码测试了Color32,并且可以正常工作。目前尚不清楚如何复制该问题。

Color uses a range from 0 to 1 for the component values.

You can construct the color using the constructor.

var darkRed = new Color(0.55f, 0, 0, 1f);

I tested Color32 using the code from your question and it worked correctly. It is unclear how to reproduce the issue.

您的好友蓝忘机已上羡 2025-02-14 06:29:19

如果您将颜色公开,那么我们可以调整检查器本身中的颜色。因此,可以轻松查看所需的颜色。您可以在更新中使用代码,并通过更改Inspector中的颜色来查看编辑器中的更改。

public class ColorTest : MonoBehaviour
{

public Color colourSelection;

// Start is called before the first frame update
void Start()
{
    //GetComponent<Renderer>().material.color = colourSelection;
}

void Update()
{
    GetComponent<Renderer>().material.color = colourSelection;
}
}

在这里检查

if you make the Color as public then we can adjust the color in the inspector itself.So it will be easy to view the color you want.You can use the code in Update and see the changes in the editor by changing the color in inspector.

public class ColorTest : MonoBehaviour
{

public Color colourSelection;

// Start is called before the first frame update
void Start()
{
    //GetComponent<Renderer>().material.color = colourSelection;
}

void Update()
{
    GetComponent<Renderer>().material.color = colourSelection;
}
}

Check here

甲如呢乙后呢 2025-02-14 06:29:19

使用具有固有的RGB/ARGB设置器的颜色类。

Color customColor = Color.FromArgb(alpha, red, green, blue);
GetComponent<Renderer>().material.color = customColor;

Use the Color class, which has an inherent RGB/ARGB setter.

Color customColor = Color.FromArgb(alpha, red, green, blue);
GetComponent<Renderer>().material.color = customColor;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文