- Home /
Horizontal Slider Normal-Background Change Color Independently
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.
Answer by Lo0NuhtiK · May 19, 2012 at 09:32 PM
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) ;
}
This code changes whole of the background. Is there a way to have two different colors in the slider i.e. on the left and right side of the thumb?
Answer by LyokoJames · Dec 14, 2012 at 04:21 PM
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.
Answer by orchard800 · Oct 18, 2015 at 08:46 PM
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);
Your answer
![](https://koobas.hobune.stream/wayback/20220613071705im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
using rgb to change color c# 1 Answer
change maincolor of texture 1 Answer
How to instantiate a prefab and change its color? 5 Answers
Customize Slider 2 Answers