我有一个很大(但可能很简单)的问题。我想显示得分。我正在使用GUI.Label。当我缩放GUI.Label时。我想设置文字的位置。我在Android上工作,所以有很多分辨率和宽高比,我有一个问题,给它一个精确的位置。
" GAME OVER"文字是精灵。我试图将位置设置为屏幕高度的一半。它适用于某些设备,但它不适用于分辨率最高的设备(1280x720)。当我从顶部设置400px它可以工作,但它没有任何意义。这有什么提示吗?我想显示像here这样的分数。
我的代码:
private string labelText;
public Font fontxd;
public Vector2 sizexde;
/*[HideInInspector]*/public GUIStyle styl;
public int p,hp;
static GameObject g1;
static punkt playerScript;
static float virtualWidth = 640.0f;
static float virtualHeight = 400.0f;
static Rect rece;
static Vector3 v3;
public Matrix4x4 matrixs;
static float guiRatio=Screen.width/640;
static float XD=0;
void Start() //1280x720
{
if (Screen.width > Screen.height) {
XD=Screen.width/2;
}
else{//if( Screen.height>Screen.width ){
XD=Screen.height/2;
}
rece=new Rect(10,XD, Screen.width,1);
v3 = new Vector3 (Screen.width / virtualWidth, Screen.width / virtualWidth , 1.0f);
matrixs = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, v3);
g1 = GameObject.Find("XDXDX2");
playerScript = g1.GetComponent<punkt>();
}
void OnGUI()
{
p = playerScript.punkty;
hp = playerScript.hpunkty;
labelText = "Height: " + Screen.height+"-"+Screen.height/2 + "\nWidth: " + Screen.width + "-"+Screen.width/2 ;
GUI.matrix = matrixs;
styl.normal.textColor = Color.black;
styl.font = fontxd;
styl.fontSize = 70;
GUI.Label (rece, labelText, styl);
}
答案 0 :(得分:0)
现在,您的标签位置应与分辨率无关。