我正在尝试设置GUI.Box
的背景色:
void OnGUI()
{
string LatLong;
LatLong = map.calc.prettyCurrentLatLon;
var mousePosition = Input.mousePosition;
float x = mousePosition.x + 10;
float y = Screen.height - mousePosition.y + 10;
GUI.backgroundColor = Color.red;
GUI.Box(new Rect(x, y, 200, 200), LatLong);
}
但是,该框显示为半透明的黑色,并且白色文本被柔化了,而不是不透明的白色。
答案 0 :(得分:2)
答案 1 :(得分:0)
在这个问题变老之前,我将在这里提供更优雅的解决方案。我看到了Thomas的回答,开始怀疑是否有一种方法可以不必在OnGUI循环中执行“ InitStyles”。因为理想情况下,您只想在Awake或Start或任何地方初始化GuiSkin一次,但是只初始化一次,然后再也不要检查它是否为null。
无论如何,经过一番反复尝试之后,我想到了这个。
private void Awake() {
// this variable is stored in the class
// 1 pixel image, only 1 color to set
consoleBackground = new Texture2D(1, 1, TextureFormat.RGBAFloat, false);
consoleBackground.SetPixel(0, 0, new Color(1, 1, 1, 0.25f));
consoleBackground.Apply(); // not sure if this is necessary
// basically just create a copy of the "none style"
// and then change the properties as desired
debugStyle = new GUIStyle(GUIStyle.none);
debugStyle.fontSize = 24;
debugStyle.normal.textColor = Color.white;
debugStyle.normal.background = consoleBackground;
}