change material and light color with horizontal slider

Hi people and sorry for such noob question. Spent hours in the doc and searching here but only found parts of answers.

I want to basically simulate LED lamp and being able to change RGB values of :

  • a material (on an lamp object)
  • a light
    This with three horizontal sliders.

At this point I’m fighting with the material stuff.

I created the following script and attached it to the object “lamp” :

var customSkin : GUISkin;
var hSliderValue : float;
var material : UnityEngine.Material;


function OnGUI () {
	GUI.skin = customSkin;
	
	hSliderValue = GUILayout.HorizontalSlider (hSliderValue, 0.0, 255.0);
	renderer.material.color.b = hSliderValue;
}

This is the first slider for blue value. Off course the code should include 2 other sliders for R and G but yet this one does not work…

1/ The slider doesn’t affects the good material. Actually the object has two and the slider affects only the first in the Material Render list), that although although I setted a material var here and selected the good one in the inspector

2/ There is no gradual changing. Wherever I drag the slider the material appears with value setted in editor for hSliderValue and only straight become yellow when slider is at the left end of the bar.
3/ I don’t understand how I can exactly set the position and size of the slider on screen. It’s okay to give it a customized look with images via the GuiSkin but how can it be sized / placed ? Cant’ just see where is mentionned that it is currently displayed at the upper-left of the screen. Tried to use Rec (position, size) in the code but seems I did not do it the good way (bug message).

4/ At the end : how could this slider code also affect a light’s color (also using r,g,b so that it’s possible to cut it off) while at present the “OnGUI” function itself is attached to a GameObject (the lamp) ?

Sorry for so many issues… Do my best but I’m not a developer at all.
Thanx by advance for help.

OK I solved a part of it with another code I found in the doc.

This one allow to change RGB values of the light.

Still the problem is that :
1/ this is attached to the light… how could it also change an object’s material color ?
2/ How can I use 3 different thumbs for the R, G and B sliders as here I use only one customized GuiSkin ? I can create 2 others but then how should the code be changed ?

There is an example of a re-usable RGB slider in the manual.

Thanx but as mentionned above I already saw this one and re-used it.

Now I got almost everything but still miss one.

This code is attached to a Null (empty game object) and the variables here allow to affect material color as well as light one.
Still miss something : here I only use ONE GuiSkin so the three sliders all have same look.

How can I include three different GuiSkins there so each slider has a thumb with appropriate color (R, G and B of course) ?

If you look at some of the examples, you can assign different GUIStyles or simply overload the function with different backgrounds, etc (GUIContent)… all within one GUISkin.

Heeere I am !:razz:
well I wonder if this code could not be simplier but at least it works.

See it there.

Final Code :

var customStyle : GUIStyle;
var customStyle0 : GUIStyle;
var customStyle1 : GUIStyle;
var customStyle2 : GUIStyle;
var myColorR : Color;
var myColorG : Color;
var myColorB : Color;
var myLight : Light;
var myMaterial : Material;
var myColorRGB : Color;

function OnGUI () {
	GUI.skin.horizontalSlider = customStyle;
	GUI.skin.horizontalSliderThumb = customStyle0;
	myColorR = RSlider (Rect (10,450,255,10), myColorR);
	
	GUI.skin.horizontalSlider = customStyle;
	GUI.skin.horizontalSliderThumb = customStyle1;
	myColorG = GSlider(Rect (10,470,255,10), myColorG);
	
	GUI.skin.horizontalSlider = customStyle;
	GUI.skin.horizontalSliderThumb = customStyle2;
	myColorB = BSlider (Rect (10,490,255,10), myColorB);
}

function RSlider (screenRect : Rect, rgb : Color) : Color {
	rgb.r = GUI.HorizontalSlider (screenRect, rgb.r, 0.0, 1.0);
	return rgb;	
}
function GSlider (screenRect : Rect, rgb : Color) : Color {
	rgb.g = GUI.HorizontalSlider (screenRect, rgb.g, 0.0, 1.0);
	return rgb;	
}
function BSlider (screenRect : Rect, rgb : Color) : Color {
	rgb.b = GUI.HorizontalSlider (screenRect, rgb.b, 0.0, 1.0);
	return rgb;	
}

function Update () {
	myColorRGB = myColorR + myColorG + myColorB;
	myLight.color = myColorRGB;
	myMaterial.color = myColorRGB;
}

Thanx for advices mate, did not gave me ready-to-use solution but the direction to look at so I could find it myself.