/// <summary> /// Fixes some switching scene bugs. /// </summary> public void Awake() { hotbarList.Clear(); selectedItemSlot = null; ItemGameObjects = null; itemEquips.Clear(); }
/// <summary> /// Get the hotbar slots from inventoryList /// </summary> /// <param name="inventoryList">The list of the inventory with all the item slots</param> public static void GetHotbarItemSlots(List <InventoryManager.ItemSlot> inventoryList) { for (int i = 4; i >= 0; i--) { hotbarList.Add(inventoryList[i]); } selectedItemSlot = hotbarList[0]; }
/// <summary> /// <para>If the player is scrolling up, equip the hotbar slot to the left</para> /// If the player is scrolling down, equip the hotbar slot to the right /// </summary> public void Update() { if (Cursor.lockState == CursorLockMode.Locked) { if (Input.mouseScrollDelta.y != 0) { if (Input.mouseScrollDelta.y < 0) //Scroll down { if (selectPos == 4) { selectPos = 0; } else { selectPos += 1; } } else if (Input.mouseScrollDelta.y > 0) //Scroll up { if (selectPos == 0) { selectPos = 4; } else { selectPos -= 1; } } } if (Input.GetKeyDown(KeyCode.Alpha1)) { selectPos = 0; } if (Input.GetKeyDown(KeyCode.Alpha2)) { selectPos = 1; } if (Input.GetKeyDown(KeyCode.Alpha3)) { selectPos = 2; } if (Input.GetKeyDown(KeyCode.Alpha4)) { selectPos = 3; } if (Input.GetKeyDown(KeyCode.Alpha5)) { selectPos = 4; } //If new select position is not the same as the old select position if (selectPos != oldSelectPos) { oldSelectPos = selectPos; selectHighlight.transform.position = new Vector3(selectPos * 60 + 25, 25, 0) + InventoryManager.offsetHotbar; selectedItemSlot = hotbarList[selectPos]; } } DoItemEquips(); }