public void Fire() { charging = false; // Spawn the overworld object and throw it PlayerItemSlot itemSlot = GetCurrentItem(); if (itemSlot == null || itemSlot.empty) { } else { Item item = itemSlot.item; itemSlot.RemoveItems(1); GameObject itemProjectile = itemGen.GetOverworldItem(item); Vector3 launchPoint = transform.position; Vector2 chrDir = Character.DirToVector(player.direction); launchPoint.x += chrDir.x * 2; launchPoint.y += chrDir.y * 2; itemProjectile.transform.position = launchPoint; Vector2 throwVelocity = chrDir * currentMagnitude; itemProjectile.GetComponent <Rigidbody2D>().velocity = throwVelocity; itemProjectile.GetComponent <Rigidbody2D>().angularVelocity = Random.Range(-1 * angularMagnitude, angularMagnitude); UIManager.Instance.UpdateSelectedItem(index); } currentMagnitude = 0; }
public void UpdateSelected() { if (this.selectedItemIndex != -1) { PlayerItemSlot itemSlot = this.itemSlots[this.selectedItemIndex]; if (itemSlot.empty || itemSlot.item == null) { this.selectedItemIndex = -1; } } bool selected = this.selectedItemIndex != -1; if (!selected) { this.selectedItemTitleText.text = ""; this.selectedItemDescriptionText.text = ""; this.selectedBorder.gameObject.SetActive(false); useButton.Interactable = false; this.selectedItemImage.gameObject.SetActive(false); } else { this.selectedBorder.gameObject.SetActive(true); PlayerItemSlot itemSlot = this.itemSlots[this.selectedItemIndex]; this.selectedItemTitleText.text = itemSlot.itemModel.displayName; this.selectedItemDescriptionText.text = itemSlot.itemModel.description; itemSlot.item.player = player; useButton.SetAction(itemSlot.item.Use); selectedBorder.transform.SetParent(itemSlot.itemSlotImage.transform, false); useButton.Interactable = itemSlot.item.usable && selected; this.selectedItemImage.sprite = itemSlot.itemSlotImage.sprite; this.selectedItemImage.gameObject.SetActive(true); } UIManager.Instance.UpdateSelectedItem(UIManager.Instance.selectedIndex); }