2016-10-11 40 views
0
void OnGUI() { 

     if (GUI.Button (new Rect (0,maxY, 100,100), "Saldır")) { 
      anim.SetBool("Bekle", false); 
      anim.SetBool("Saldir", true); 
     } 
    } 

這是我的代碼。 我想在GUI屏幕中獲得最大的Y位置?怎麼辦?如何獲得Unity GUI最大x,y位置?

回答

1

您可以使用Screen.height來獲得屏幕的最大Y值。在你的情況,我會說Screen.height - 100,因爲你必須減去按鈕的高度,以使其可見。

顯然,Screen.width爲X值。

0

如果這是關於縮放。使用畫布。

,但如果你必須使用(舊)圖形用戶界面,採用了矩陣:

 public void OnGUI(){ 
//First thing is the matrix 
      GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.width/1280, Screen.height/720, 1)); 

    //code 
     } 

http://answers.unity3d.com/questions/169056/bulletproof-way-to-do-resolution-independant-gui-s.html

https://docs.unity3d.com/ScriptReference/GUI-matrix.html

,並回答你的問題用途:

Screen.width Screen.height

相關問題