/// <summary> /// Called once every frame. /// </summary> void Update() { if (isEquipped && !Input.GetKey(KeyCode.N)) { SetActiveUI(true); if (Input.GetKeyDown(KeyCode.Mouse0)) { int remaining = currentThrowable.Throw(); text.text = currentThrowable.Name + ": " + remaining; //No more throwables available of currentType. if (remaining == 0) { string newType = PlayerItems.GetNextThrowable(); if (newType == null) { //Unequip if no throwables available. isEquipped = false; } else { //Equip another throwable type. currentThrowable = inventory.GetThrowable(newType); text.text = newType + ": " + PlayerItems.GetThrowableCount(newType); } } } } else { SetActiveUI(false); } }
/// <summary> /// Update button text with the count of this throwable in the inventory. /// </summary> public void UpdateButton() { int count = PlayerItems.GetThrowableCount(throwable.name); buttonText.text = throwable.name + ": " + count.ToString(); if (count == 0) { button.enabled = false; } else { button.enabled = true; } }
/// <summary> /// Activate or equip the throwable and make it ready for throwing. /// </summary> /// <param name="name"> The throwable type to equip. </param> public void Activate(string name) { isEquipped = true; text.text = name + ": " + PlayerItems.GetThrowableCount(name); currentThrowable = inventory.GetThrowable(name); }