Quantcast
Channel: Latest Questions by betaFlux
Viewing all articles
Browse latest Browse all 30

zoom problem with GUI Box that follows a character

$
0
0
I have a GUI box following a sprite character in a 2d Top Down Game. If I zoom in, the GUI box goes up, if I zoom out, the GUI box moves down, instead of staying at the point it was drawn at game start. Have a look at the image below. ![alt text][1] Some more details: - the camera is in orthographic mode (although the same happens in perspective mode) - the camera zoom is done by changing its OrthographicSize-value This is the code I use to draw the GUI: void OnGUI() { GUI.skin = guiSkin; boxPosition = Camera.main.WorldToScreenPoint(baseAgent.transform.position); guiSkin.box.fontSize = fontSize; nameLabelText = baseAgent.name; Vector2 content = guiSkin.box.CalcSize(new GUIContent(nameLabelText)); Vector3 boxPosition = new Vector3(Mathf.Clamp(boxPosition.x, 0 + (content.x / 2), Screen.width - (content.x / 2)), Mathf.Clamp(boxPosition.y, 40, Screen.height), boxPosition.y); GUILayout.BeginArea(new Rect((boxPosition.x + offsetX) - (content.x / 2), (Screen.height - boxPosition.y) + offsetY, content.x, content.y)); GUILayout.BeginHorizontal(); GUILayout.Box(nameLabelText); GUILayout.EndHorizontal(); GUILayout.EndArea(); } [1]: /storage/temp/43254-gui-zoom-problem.png Any clue on what might solve the issue would be greatly appreciated! Thanks!

Viewing all articles
Browse latest Browse all 30

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>