- Home /
Question by
kmccmk9 · Mar 12, 2012 at 04:18 AM ·
floatslidervaluehorizontal
Slider issues
Hello, I'm trying to create 3 sliders to control the rgb elements of a material. However, using this code below the shaders show up and work but act as though there is only two settings. On or off. It should be a gradual change and I know from debugging that the slider is returning proper float variables so why is it not applying the right colors to my material? The second code is the code I'm using to obtain the rgb values and apply them to my material.
//HairColorSlider
if (haircolorcount == 1)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Red:");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
haircolorrslider = GUILayout.HorizontalSlider(haircolorrslider,0.0F,255.0F);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Green:");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
haircolorgslider = GUILayout.HorizontalSlider(haircolorgslider,0.0F,255.0F);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Blue:");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
haircolorbslider = GUILayout.HorizontalSlider(haircolorbslider,0.0F,255.0F);
GUILayout.EndHorizontal();
debuglabel = "R:" + haircolorrslider + " G:" + haircolorgslider + " B:" + haircolorbslider;
FemaleHairStyle1Script.ChangeColor(haircolorrslider,haircolorgslider,haircolorbslider);
}
if (haircolorcount == 2)
{
haircolorcount = 0;
}
public void ChangeColor(float rvalue, float gvalue, float bvalue)
{
//Color materialcolor = new Color(rvalue,gvalue,bvalue,1);
materialcolor.r = rvalue;
materialcolor.g = gvalue;
materialcolor.b = bvalue;
foreach(Renderer part in r)
{
part.material.color = materialcolor;
}
}
Comment
Best Answer
Answer by Berenger · Mar 12, 2012 at 06:34 AM
Color components are [0..1], your sliders are [0..255]