gpt4 book ai didi

unity3d - Unity - 设置 GUI.Box 背景颜色

转载 作者:行者123 更新时间:2023-12-05 01:33:42 24 4
gpt4 key购买 nike

我正在尝试设置 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);
}

但是,该框显示为半透明的黑色,而白色文本是柔和的,而不是不透明的白色。

enter image description here

最佳答案

你必须使用 s gui 样式:

private GUIStyle currentStyle = null;

void OnGUI()
{
InitStyles();
GUI.Box( new Rect( 0, 0, 100, 100 ), "Hello", currentStyle );
}

private void InitStyles()
{
if( currentStyle == null )
{
currentStyle = new GUIStyle( GUI.skin.box );
currentStyle.normal.background = MakeTex( 2, 2, new Color( 0f, 1f, 0f, 0.5f ) );
}
}

private Texture2D MakeTex( int width, int height, Color col )
{
Color[] pix = new Color[width * height];
for( int i = 0; i < pix.Length; ++i )
{
pix[ i ] = col;
}
Texture2D result = new Texture2D( width, height );
result.SetPixels( pix );
result.Apply();
return result;
}

取自unity forum .

关于unity3d - Unity - 设置 GUI.Box 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64459671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com