x


using rgb to change color c#

I am trying to change an objects color through 3 sliders that are red, blue and green. i have a code setup where there is 3 Gui sliders that effect floats:

 rSliderValue = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), rSliderValue, 0.0F, 255.0F);
 bSliderValue = GUI.HorizontalSlider(new Rect(25, 50, 100, 30), bSliderValue, 0.0F, 255.0F);
 gSliderValue = GUI.HorizontalSlider(new Rect(25, 75, 100, 30), gSliderValue, 0.0F, 255.0F);

then lower down in my script i have some code that changes the color like this:

 renderer.material.color = Color32(rSliderValue, bSliderValue, gSliderValue, 1);

im getting an error saying: Assets/Color_Change.cs(37,67): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

can anyone explain why this error is occurring as i cannot make sense of what the error is meant to tell me.

-Thanks, Harry

more ▼

asked Oct 10, 2013 at 06:59 AM

HarryGodden gravatar image

HarryGodden
27 5 899 9

You don't write "solved" in the title to accept answers. Please watch the tutorial video (link on the right) if you don't know how to use this site.

Oct 10, 2013 at 04:48 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Add 'new' before color:

 renderer.material.color = new Color32(rSliderValue, bSliderValue, gSliderValue, 1);

Because you did not say 'new', the compiler looks at Color32 as the type instead of a value of a type.

So you where trying to make the type Color32 equal to something.

Where you actually need a variable of type Color32 to equal something.

I hope that made it clear.

more ▼

answered Oct 10, 2013 at 07:00 AM

dorpeleg gravatar image

dorpeleg
2.7k 106 95 105

hey, thanks for your response, but i am now getting another error using that code:

Assets/Color_Change.cs(37,123): error CS1502: The best overloaded method match for UnityEngine.Color32.Color32(byte, > byte, byte, byte)' has some invalid > arguments and this one too: > Assets/Color_Change.cs(37,123): error > CS1503: Argument #1' cannot convert float' expression to type byte'

is this because i am using floats not bytes? and how would i change a float to a "byte" or instead change the slider to output a byte?

-Harry

Oct 10, 2013 at 03:34 PM HarryGodden

Is there a reason you are using Color32 instead of Color? Color accepts floats between 0 and 1.

Oct 10, 2013 at 03:37 PM CoalCzar

oh yeah, that fixed it, thanks!

-Harry

Oct 10, 2013 at 03:48 PM HarryGodden

Please mark as answered them :)

Oct 10, 2013 at 04:24 PM dorpeleg
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1436
x942
x587
x182

asked: Oct 10, 2013 at 06:59 AM

Seen: 4894 times

Last Updated: Oct 10, 2013 at 04:48 PM