void updateCurrentHeld() // make sure currentheld is within inventory count { if (spellsInventory.Count == 0) // shut everything off { currentHeld = 0; foreach (Transform child in spellSlots) { child.Find("Title").GetComponent <Text>().text = "Empty Spell Slot"; spellslot data = child.GetComponent <spellslot>(); data.Deselect(); } } else // update the ammo gauge and makesure current held is within inventory count { if (currentHeld >= spellsInventory.Count) { currentHeld = 0; } else if (currentHeld < 0) { currentHeld = spellsInventory.Count - 1; } foreach (Transform child in spellSlots) { spellslot data = child.GetComponent <spellslot>(); if (child.GetSiblingIndex() == currentHeld) { SpellBook currSpell = spellsInventory[currentHeld]; data.Select(currSpell.spellTitle, currSpell.spellDescription, currSpell.getAmmo(), currSpell.getMaxAmmo(), currSpell.baseColor); } else { if (child.GetSiblingIndex() >= spellsInventory.Count) { data.setTitle("None Held"); } data.Deselect(); } } } }
public void fireSpell() // Shoot the spell { if (!canFire) { return; } // If cooling down spellsInventory[currentHeld].primaryEffect.ActivateSpell(this, spellsInventory[currentHeld].secondaryEffect, Head.forward); // activate currently held spellbook spellsInventory[currentHeld].useAmmo(); // the player uses ammo in a spellbook spellslot data = spellSlots.GetChild(currentHeld).GetComponent <spellslot>(); data.modifyDetails(spellsInventory[currentHeld].spellTitle, spellsInventory[currentHeld].spellDescription, spellsInventory[currentHeld].getAmmo(), spellsInventory[currentHeld].getMaxAmmo(), spellsInventory[currentHeld].baseColor); // data.ammoBarInner.fillAmount = (float)spellsInventory[currentHeld].getAmmo() / spellsInventory[currentHeld].getMaxAmmo(); // Calculate and initiate cooldown float coolDown = spellsInventory[currentHeld].primaryEffect.coolDown; coolDown += spellsInventory[currentHeld].secondaryEffect.coolDown; StartCoroutine(fireCoolDown(coolDown)); }