Hello,
I am new to Unity and I need to help.
How can I make the Horizontal Slider Normal-Background color change independently?
For example I want to make volume slider, when user slide the thumb more to the right (volume high), the background will more become to red.
Thank you.
Could give your GUIStyle a plain-white background image for your horizontal slider,
then just have your background color change along with your volume.
e.g :
//whatever you're doing with your volume stuff...
void OnGUI(){
GUI.backgroundColor = new Color(currentVolume, 0f,0f,1f) ;
currentVolume = GUILayout.HorizontalSlider(currentVolume, 0f, 1f) ;
}
I think you just want the slider as a whole to have a gradient background that goes from white to red, in that case, design a background image with another program and use that image as the slider background, if that’s possible.
Try this on the slider’s fill image:
// Interpolate the colour of the bar between the chosen colours, based on the current percentage of the starting volume.
fillImage.color = Color.Lerp (zeroVolumeColour, fullVolumeColour, currentVolume / startingVolume);