- Home /
Window with opaque background
I am trying to display a ModalWindow with an opaque red background. So far, I have read enough posts and documentation to understand that I need to define a custom GUIStyle for the window and that the property to set is the normal.background to a texture filled with the desired color. However, I have been unable to either achieve that or understand why it does not work. The code is the following:
using UnityEngine;
public class OpaqueWindowTest: MonoBehaviour {
private GUIStyle windowStyle = new GUIStyle();
void Start() {
Texture2D bg = new Texture2D(1, 1);
bg.SetPixel(0, 0, new Color(1.0f, 0.0f, 0.0f, 1.0f));
windowStyle.normal.background = bg;
}
void OnGUI() {
GUI.ModalWindow(
1,
new Rect(100, 100, 320, 240),
WndProc,
GUIContent.none,
windowStyle
);
}
void WndProc(int windowID) {
// display stuff here...
}
}
The window is indeed displayed without the standard chrome and with a uniformly colored background, but that background is semi-transparent and white, not opaque and red as I'd expect.
Any suggestions as to why the above code does not work as intended and how to achieve the desired result?
Your answer
Follow this Question
Related Questions
Editor Window Update 1 Answer
Color custom editor window ? 2 Answers
How can I tell when the Unity window is inactive? 1 Answer
How to hide game window but show sprite? 0 Answers