- Home /
Vertical Slider - Using different art?
Currently I have a vertical slider in a scene controlling the volume of audio playing and it works quite well. I'm using the Unity GUI for the slider and it's not incredibly attractive. I know you can customize the look of the GUI to an extent, but is it possible to use art assets for the slider? Like maybe a 2D image of a slider and another 2D image of the track that it would run on? Sorry for what's probably an ignorant question, but I haven't found much info on how to do this. Does anyone have any tips? Should I not use the GUI at all for this and just pass a value of where the slider image or model currently is and use that to set the volume?
Thanks for the help!
Look up GUIstyles in the reference manual. That's what you need, here.
Thanks for pointing me in the right direction!
http://unity3d.com/support/documentation/Components/class-GUIStyle.html
I also read the page describes the different GUIStyle parameters you can set for the sliders. Here are the parameters I was looking for:
slider The GUIStyle to use for displaying the dragging area. If left out, the horizontalSlider style from the current GUISkin is used.
thumb The GUIStyle to use for displaying draggable thumb. If left out, the horizontalSliderThumb style from the current GUISkin is used.
I'm having trouble figuring how to point these two parameters to the image I want to use. Does anyone have any suggestions? This is my first go at using the Unity GUI. Everything I've read about people trying to use images for the thumbs and sliders was about how they couldn't figure it out.
Answer by imnickb · Apr 04, 2012 at 12:51 PM
After some trial and error and found an answer. In case anyone with the same issue finds this question, here's what I found:
Add variables for the GUIstyles you plan to use.
var vthumbStyle : GUIStyle;
var vsliderStyle : GUIStyle;
Find the script with GUI Styles you're using in the scene.
Assign the images you want to use for the sliders to Background under Normal.
In your script where you create the sliders, reference the GUI Style you created.
function OnGUI () {
vSliderValue = GUI.VerticalSlider (Rect (327, 125, 15, 300), vSliderValue, 10.0, 0.0,vsliderStyle,vthumbStyle);
}
The next part is what was kind of confusing because I didn't see it in the documentation anywhere. In the GUI Style you're using in the inspector, you need to add the dimensions of the images you're using under Fixed Height and Fixed Width. It also helped me to make the images the same height, so that the Thumb and Slider line up easily with each other. I hope this helps someone!