简体   繁体   中英

new Color C# (in Unity)

double red = loc[1] * 25.5;
newBlock.GetComponent<Renderer>().material.color = new Color((float)red, 0, 0);

When I apply this new Color to a variety of cubes in Unity, and loc[1] is a number between 0 and 10, all of the cubes are white, rather than varying shades of red. Why is this?

Color uses value between 0 and 1.

You need to normalize the given values.

 new Color(255f/255f, 100f/255f, 0f/255f);

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