diff --git a/Assets/Scripts/HouseController.cs b/Assets/Scripts/HouseController.cs index d8c8733..c263717 100644 --- a/Assets/Scripts/HouseController.cs +++ b/Assets/Scripts/HouseController.cs @@ -31,20 +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); - + float newPosX = pos.x; + float newPosY; + 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); + menuPanel.transform.position = new Vector3(newPosX, newPosY); } - - } } \ No newline at end of file diff --git a/Assets/Scripts/ItemContainer.cs b/Assets/Scripts/ItemContainer.cs index 5f6c5fc..a62ff92 100644 --- a/Assets/Scripts/ItemContainer.cs +++ b/Assets/Scripts/ItemContainer.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using UnityEngine; public class ItemContainer : MonoBehaviour { @@ -18,12 +19,22 @@ public class ItemContainer : MonoBehaviour { #endregion - public Item[] allItems; - // Start is called before the first frame update + private List _allItems; + + private void Start() { + string[] files = + Directory.GetFiles("Assets/Items", "*.cs", SearchOption.AllDirectories); + foreach (string file in files) { + _allItems.Add(Resources.Load("Assets/Items/" + file)); + } + Debug.Log(files); + Debug.Log(_allItems); + } + public Item GetItemByName(String name) { - for (int i = 0; i < allItems.Length; i++) { - if (allItems[i].displayName == name) { - return allItems[i]; + for (int i = 0; i < _allItems.Count; i++) { + if (_allItems[i].displayName == name) { + return _allItems[i]; } }