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)
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
}
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.
Why the -1?
– xSpectrumYeah, 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 =]
– AlucardJayHi 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.
– Noah-1Edited my answer. That should work, but please note I haven't tested it out myself. Just let me know if it doesn't work.
– xSpectrumHey great script man, I just edited it a bit to fit my needs and it´s working! perfectly on my GUI controlls.
– Noah-1