Beginner - Slider changing color

Hello, i have script for Horizontal slider which changes the color of model, but it change only four colors.
Here is script
Put the script on a cube

var slider : float;



function OnGUI () {

   slider = GUI.HorizontalSlider( Rect(20,135,175,30), slider, 0.0, 20.0);

   renderer.material.color.b = slider;

}

And i need slider to change all colors.
Please help me with this

Add code for red an green also. “renderer.material.color.b = slider;” only change the blue color.
Or better yet add 2 new sliders that control red and green.

Okay, i made a three sliders, but only sliderc changing color.

var slidera : float;

var sliderb : float;

var sliderc : float;



function OnGUI () {

   slidera = GUI.HorizontalSlider( Rect(20,135,175,30), slidera, 0.0, 20.0);

   renderer.material.color.b = slidera;

   

   sliderb = GUI.HorizontalSlider( Rect(20,160,175,30), sliderb, 0.0, 20.0);

   renderer.material.color.b = sliderb;

   

   sliderc = GUI.HorizontalSlider( Rect(20,185,175,30), sliderc, 0.0, 20.0);

   renderer.material.color.b = sliderc;

}

I guess you have no idea what a color is :slight_smile:
A color is an object with 3 or 4 values that actually influence the color you see.
color.r = the quanty of red in your color
color.g = the quantity of green in your color
color.b = the quantity of blue in your color
color.a = the transparence of your color, a stands for alpha

So change the
renderer.material.color.b in renderer.material.color.r and renderer.material.color.g in two of the sliders

Thanks so much!!! And i have one more question. I have scene1 with cube and this sliders and button play, when you press play it load scene2 with the same cube, and i need the colors of the scene1 loaded in scene2. Can you still help me with this?

Look for DontDestroyOnLoad function.

Thanks i go look it

I looked at it, but I do not know how to do that was what I needed.

Please can anyone help me with this script?

Stop uselessly bumping your thread. scarpelius provided the correct solution and the Script Reference gives example code…

Ok, I’m sorry