Change Color in C# with RGB Values?

Hi everyone,
I’ve been writing a script in C# to change the color of an object when pressing down a key on the keyboard, and that works fine if the code is written like this:

	void Update ()
			{
						if(Input.GetKeyDown(KeyCode.R))
						{
								gameObject.GetComponent<Renderer>().material.color = Color.red;
						}
			}

However, instead of changing the color to Red, I want to change it to a color with certain RGB values. (233, 79, 55) Is there a way to do this? I’ve tried everywhere, but I can’t seem to find anything.

Thanks.

EDIT: Ok. So I think I’m getting somewhere. I’ve tried creating a script:

			void Update ()
			{
						if(Input.GetKeyDown(KeyCode.R))
						{
								gameObject.GetComponent<Renderer>().material.color = new Color(233, 79, 55);
						}
			}

I think this might work, however when I test the game it changes the material color to white. Does anyone know what I can do to fix it?

The problem with your updated script: You pass values above 1.0 to a variable of type Color, which takes values from 0.0 to 1.0, so it ignores anything higher than that and treats it as 1.0. That’s why your color is white in the game.
The solution is simple: Use Color32 instead, which takes a value from 0 to 255.

Lets say you’ve come up with the perfect shade of grey (or gray). In the color picker, you note that “Perfect Grey” is “ADADAD” and the Alpha is 200. In your game, the myGameObject’s color gets changed to Red for whatever reason, but later, your GameObject is newly invigorated and its color must change back to “Perfect grey”. The call to do this is:

myGameObject.color = new Color32( 173, 173, 173, 200 );

Where did the 173 values come from? The “AD” in the color picker is a hex value. Convert that to a decimal and you have “173”. If you didn’t get a BS in Computer Science and/or can’t convert that in your head, there are any number of Hex to Decimal converters on line. The Alpha (opacity) value “200” is conveniently displayed in the color picker as a decimal.

@Matthew.OC But in Color32 ,there is a 4th argument which is a or transparency.

The Color class uses values from 0 to 1, not 0 to 255. So your color should be

 new Color(0.91, 0.3, 0.21);