- Home /
GUI.DrawTexture with opacity
Hello! Please help me to draw the fullscreen texture with necessary level of opacity (I need to make fading animation for it).
Answer by Cyb3rManiak · Jun 02, 2011 at 08:24 AM
You can also alter the GUI.color (specifically GUI.color.a) right before the call to GUI.DrawTexture() to determine the transparency. Just make sure to return it to the previous color after it if you draw anything else. You can even make the entire GUI fade away, buttons and all...
This works just fine:
using UnityEngine;
using System.Collections;
public class GUITest : MonoBehaviour
{
public Texture2D txForeground;
public float fAlpha;
void OnGUI()
{
// Unless you changed it, the default for GUI.color is Color.white, but better be safe than sorry.
// Just save the previous color and restore it after you draw whatever you want to be transparent.
Color colPreviousGUIColor = GUI.color;
GUI.color = new Color(colPreviousGUIColor.r, colPreviousGUIColor.g, colPreviousGUIColor.b, fAlpha);
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), txForeground);
GUI.color = colPreviousGUIColor;
}
}
Answer by Edy · Jun 02, 2011 at 08:12 AM
You can specify the the opacity of a texture by setting each pixel's alpha value. However this is quite slow for fading animations (requires many SetPixel calls), so you'd better use a regular Plane (GameObject > Create other > Plane) in front of the camera showing the texture. You can change the transparency by setting the Alpha value for the base color (ensure to use a transparent material).
Answer by alyabov · Jun 02, 2011 at 08:22 AM
ОК, I'll try it. Or maybe Graphics.DrawTexture can help? It has Material and Color in parameters list. So maybe I can to change alpha channel using it?
Answer by alyabov · Jun 02, 2011 at 08:29 AM
Very good idea. Do this function change all GUI elements? I have 6 textures on the screen and each of them must have different opacity level.
Oh, I understand how it works. Thanks to all for help!
Your answer
Follow this Question
Related Questions
Opacity for DrawTexture not working 1 Answer
Can the editor play in full screen? 3 Answers
Webplayer: Switch to fullscreen via HTML-Button? 1 Answer
unity web player fatal error couldn't switch to requested monitor resolution 1 Answer
Standalone player in windows open fullscreen, but player settings says windowed 1 Answer