public void OpenInventory() { if (menuOpen == false && controll.menuOpen == false) { int id = inv.FetchInventoryBySlug(hotspot.Slug).ID; inventoryPanelRef = Resources.Load <GameObject> ("Prefab/InvMenu_" + (inv.database[id].ItemsAndSize.Count).ToString()); GameObject inventoryPanel = Instantiate(inventoryPanelRef); //RectTransform invPanelRect = inventoryPanel.GetComponent<RectTransform>(); inventoryPanel.GetComponent <UIStayInPlace>().pos = gameObject.transform.position; inventoryPanel.GetComponent <UIStayInPlace>().offset = new Vector3(0, 300, 0); //this might change if you change the camera y offset -- inventoryPanel.name = hotspot.Slug + "_inv"; inventoryPanel.transform.SetParent(GameObject.FindGameObjectWithTag("Main Canvas").transform, false); inventoryPanel.transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position) + new Vector3(0, 300, 0); inventoryPanel.transform.localScale = Vector3.one; Button button = inventoryPanel.transform.GetChild(0).GetComponent <Button>(); button.onClick.AddListener(CloseInventory); // instantiate inv panel here for (int i = 0; i < inv.database[id].ItemsAndSize.Count; i++) { slots.Add(Instantiate(inventorySlot)); slots [i].transform.SetParent(inventoryPanel.transform); slots [i].transform.localScale = Vector3.one; slots [i].GetComponent <SlotBehaviour>().invID = id; slots [i].GetComponent <SlotBehaviour>().slotID = i; if (inv.database[id].ItemsAndSize[i] != -1) { GameObject itemObj = Instantiate(inventoryItem); itemObj.GetComponent <ItemData> ().itemData = itemDatabase.FetchItemByID(inv.database[id].ItemsAndSize[i]); itemObj.GetComponent <ItemData> ().itemAmount = inv.database[id].ItemsAmount[i]; itemObj.transform.SetParent(slots [i].transform); itemObj.GetComponent <Image> ().sprite = itemObj.GetComponent <ItemData> ().itemData.Sprite; itemObj.transform.position = Vector2.zero; itemObj.transform.localScale = Vector3.one; if (itemObj.GetComponent <ItemData> ().itemAmount > 1) { itemObj.transform.GetChild(0).GetComponent <Text> ().text = (itemObj.GetComponent <ItemData>().itemAmount).ToString(); } } } button.transform.SetAsLastSibling(); menuOpen = true; controll.menuOpen = true; } }