简体   繁体   中英

How do I get the RGB value of a material in unity?

I have a script attached to a cube and I don't know how to get the RGB value from it's material. So far I've fetched the renderer with Renderer rend = GetComponent<Renderer>(); . Any idea how I could do this?

Unity c# is rusty but try this, hope it works.

Color32 objColor;

objColor = gameObject.GetComponent<MeshRenderer>().material.color;
print(objColor.r + " "+ objColor.g + " "+ objColor.b+ " "+ objColor.a + " ");

Get back to me if it doesn't work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM