- Home /
Changing GUI.Box opacity
How do you change the opacity of a GUI.Box? Is it even possible?
Answer by BMayne · Sep 01, 2014 at 01:55 AM
Hey There,
All you have to do is go
GUI.Color = new Color(1.0f, 1.0f, 1.0f, 0.5f) //0.5 is half opacity
GUI.Box()
GUI.Color = Color.white;
Unity is a state machine so you want to set it back to white when you are done. This GUI.Color effects every GUI element.
Regards,
This doesn't work anymore. It changed the text color ins$$anonymous$$d of the box.
It always changed both. GUI.color is a global color multiplier which affects both, the background as well as the foreground. In addition there's the GUI.backgroundColor which only affects the background as well as GUI.contentColor which only affects the foreground.
Answer by MFen · Dec 05, 2013 at 09:32 PM
If you want to change the default GUI.Box you will need to create your own GUISkin inside of the unity editor. Once you have done that click on it and at the top in the inspector window you will see box, change the values of the colors for whatever options you would like. Once you have done that whatever script you are using for GUI, add a holder to put your GUISkin in and in your OnGUI class add GUI.skin = myGUI;
@$$anonymous$$fen: I am new to this GUISkin stuff. Could you show me some example code and possibly explain this with a more detailed context? Thank you.
Answer by roryo · Sep 01, 2014 at 01:43 AM
You can make the box more transparent using the opacity in a GUI.Color.
However, to increase the opacity (which is otherwise limited to the opacity of the Box texture image), you can avoid making a new box image and skin by calling the same GUI.Box rectangle multiple times. For example, call the GUI.Box twice and you double its opacity.
function OnGUI () {
GUI.Box (Rect (0, 0, Screen.width/7, Screen.height/1), "");
GUI.Box (Rect (0, 0, Screen.width/7, Screen.height/1), "");
}
I also posted this hack here: http://forum.unity3d.com/threads/gui-box-transparency.44392/
Your answer
Follow this Question
Related Questions
C# GUI Destroy or Disable? 1 Answer
How do you CORRECTLY call methods from another C# file 1 Answer
Using GUI skin with my GUI Button 1 Answer
Using GUI and GUILayout at the same time 1 Answer
creating a list of texture2d components 0 Answers