Unity3Dの標準GUIを使用しています。
GUI 要素の画面位置を取得するにはどうすればよいですか?
これを試して:
var positionGui : Vector2;
positionGui = Vector2 (guiElement.transform.position.x * Screen.width, guiElement.transform.position.y * Screen.height);
あなたはこのようなことをすることができます
public static Rect screenRect
(float tx,
float ty,
float tw,
float th)
{
float x1 = tx * Screen.width;
float y1 = ty * Screen.height;
float sw = tw * Screen.width;
float sh = th * Screen.height;
return new Rect(x1,y1,sw,sh);
}
public void OnGUI()
{
if (GUI.Button(screenRect(0.4f, 0.6f, 0.2f, 0.1f), "TRY AGAIN"))
{
Application.LoadLevel(0);
}
print ("button position + framesize"+screenRect(0.4f, 0.6f, 0.2f, 0.1f));
}