House Menu position adjustment

This commit is contained in:
s-prechtl 2022-06-03 10:59:55 +02:00
parent 127ff101d8
commit a457924b6d
2 changed files with 36 additions and 19 deletions

View file

@ -12,6 +12,7 @@ public class HouseController : MonoBehaviour {
public Canvas menu;
public TextMeshProUGUI dayCountTextMeshProUGUI;
public GameObject menuPanel;
private void OnMouseDown() {
ToggleMenu();
@ -30,5 +31,20 @@ public class HouseController : MonoBehaviour {
public void ToggleMenu() {
menu.gameObject.SetActive(!menu.gameObject.activeSelf);
float newPosY;
if (Camera.main != null) {
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
if (pos.y - 50 - ((RectTransform)menuPanel.transform).rect.height >= 0) { //check if bottom of panel is in screen
newPosY = pos.y - ((RectTransform)menuPanel.transform).rect.height;
} else {
newPosY = pos.y + ((RectTransform)menuPanel.transform).rect.height;
}
menuPanel.transform.position = new Vector3(pos.x, newPosY);
}
}
}