- Home /
Use slider to modify alpha of a GUI Texture?
Hi guys, I have been working on some user interface stuff for my Mobile Game, now I want to let the user change the transparency of the GUI Controls using a slider like in the hierachy GUI Texture--> color-->sliders---> A, there is a slider to change the transparency of any GUI Texture, any ideas on how to do this but in the game view?
Check this image, I want to replicate the Alpha slider, and let the user control the transparency of the GUI Textures (Controls on the screen)
Thanks
Answer by xSpectrum · Jul 23, 2012 at 01:37 AM
It's hard to answer if we don't know what GUI elements you're using. Are you using GUITextures (images)? Labels? Boxes? Buttons? As for the slider, are you asking how you would make the slider, or how you would make the preexisting slider affect alpha?
Script to make slider affect GUITexture alpha:
var hSliderValue : float = 0.0;
function OnGUI ()
{
hSliderValue = GUI.HorizontalSlider(Rect (25, 25, 100, 30), hSliderValue, 0.0, 100.0); //make the slider, and assign the value of it to a variable
var colPreviousGUIColor : Color = GUI.color; //assign variable to current GUI color (just in case you're using a different value other than default)
GUI.color = new Color(colPreviousGUIColor.r, colPreviousGUIColor.g, colPreviousGUIColor.b, hSliderValue/100); //Assign new color to GUI, only affecting the alpha channel
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), yourTextureHere); //draw your texture(s)
GUI.color = colPreviousGUIColor; //Reset alpha and color.
DrawWithoutAlpha();
}
function DrawWithoutAlpha()
{
//put any GUI elements you don't want to be affected by alpha (or want a different alpha value) here
}
Yeah, why the -1 ? Bad form, leaving a thumb Down without even a comment. I am +1 thumb Up to this answer until someone can convince me otherwise =]
Hi guys, thanks for the quick replies, I didn´t thumbed down, I actually think that is the way to do it, about my question, you´re right I missed some points there, I am using some GUI Textures, I know how to do the sliders but I am not really sure on how to make one that works like the alpha color on the GUI.
Edited my answer. That should work, but please note I haven't tested it out myself. Just let me know if it doesn't work.
Hey great script man, I just edited it a bit to fit my needs and it´s working! perfectly on my GUI controlls.
Your answer
Follow this Question
Related Questions
Can I use a movie texture with alpha as a GUI object? 1 Answer
Crafting System - How to use a slider to show progress 0 Answers
How to make slider load variable on start 1 Answer
Alpha not working in GUITex 0 Answers
Non rectangular GUI Mask / Matte? 2 Answers