- Home /
Slider not correctly changing colorr of image.,Changing Image Color via Slider isnt working correctly
My Slider Min and Max values are 0 and 255 respectively. however the image changes color as if value is set to 255 at the slightest movement of the slider. instantly changing the color from black to Solid Red but through Debug.Log i can see that the slider values do range between 0-255 while ingame {
public GameObject Base;
public GameObject BaseDisplay;
public Slider RSlider, GSlider, BSlider;
void Update ()
{
BaseDisplay.GetComponent<Image>().color = new Color(RSlider.value,GSlider.value,BSlider.value);
}
}
Answer by Vicarian · Jun 16, 2018 at 09:33 PM
Colors are instantiated with float values for ARGB from 0 to 1. Divide your slider values by 255.
Thank you that worked! i couldn't figure out for the life of me what was going wrong. and probably never would have if it weren't for you. thanks!
The editor would have a warning in the console saying something like "Color was attempted to be used with a non-normalized value." Do make sure to pay attention to your console when developing a new aspect of your project. It does save a lot of headache sometimes.
Your answer
Follow this Question
Related Questions
Inspector changes set TextMeshPro values on play 1 Answer
Problems in the script for making a text disappear after few seconds 2 Answers
Close UI using Canvas Group 1 Answer
Unity 2D - Text UI and Textbox scripting issue - HELP ASAP! 2 Answers
Scripting button functionality inside class with created object's method 1 Answer