Reputation: 55
void OnGUI() {
if (GUI.Button (new Rect (0,maxY, 100,100 ), "Saldır")) {
anim.SetBool("Bekle", false);
anim.SetBool("Saldir", true);
}
}
this is my code. I want to get maximum Y position in GUI screen? How can do it ?
Upvotes: 0
Views: 1028
Reputation: 63
if this is about scaling. use a canvas.
but if you have to use (old) GUI, use a matrix:
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
and to answer your question use :
Screen.width Screen.height
Upvotes: 0
Reputation: 6123
You can use Screen.height to obtain the maximum Y-value for your screen. In your case, I'd say Screen.height - 100
, because you have to subtract the Button's height in order to make it visible.
Obviously, Screen.width
for the X-value.
Upvotes: 1