Changing material Color using RBG?

Just to Be clear i am using JavaScript
I am wondering if it is possible to change the color of a material using RBG values? I would like to make one GUI slider that accesses the numbers from 0-255 on R, G, B and alpha value. (That GUI slider would access all the possible colors from most right to most left.

I found this snippet of code to change the color of the material in RBG:

material.color = newColor(255f, 255f, 255f, 1);

Am I on the right track?

Thank You


If you want to use 0-255 integer values, use Color32.

material.color = Color32(255, 255, 255, 1);

newColor, as far as I know, does not exist.
Here’s a function to create a color for what you want:

   function getColor(red:int, green:int, blue:int, alpha:int):Color{
       return Color((1/255)*red, (1/255)*green, (1/255)*blue, (1/255)*alpha);

(note: not tested, but should work :slight_smile:)

To use it, simply do:

material.color = getColor(255,255,255,255);

Red, green, blue and alpha are numbers between 0 and 255.

UPDATE: As for shininess, that is up to your shader. See

Each color component is a floating point value with a range from 0 to 1.

Try :

var r : float = value / 255.0f;

Shininess would be relative to the Shader.