public void CastSpell() { // If there is no currently bound spell, just back out if (m_currentSpellSlot == null || m_currentSpellIdx == -1) { return; } // Spawn the spell FX on the target indicator's current position and rotation var targetObj = m_aimController.GetSpellSpawnPoint(); Vector3 targetPos = targetObj.transform.position; Quaternion targetRot = targetObj.transform.rotation; Instantiate(m_currentSpellSlot.m_spell.m_fxPrefab, targetPos, targetRot, null); // Disable the spell and start its cooldown m_currentSpellSlot.m_readyToUse = false; m_currentSpellSlot.m_cooldownPercentage = 0.0f; m_currentSpellSlot.m_cooldownTimeComplete = 0.0f; // Switch off the spell slot m_currentSpellSlot = null; m_currentSpellIdx = -1; // Deactivate the indicator m_aimController.DeactivateIndicator(); //ToggleSpellSlot(m_currentSpellIdx); }
public void ToggleSpellSlot(int _slotIdx) { // Grab the information about the spell slot Spell_Slot spellSlot = m_spellSlots[_slotIdx]; // Grab the actual spell object from the slot Spell_Base boundSpell = spellSlot.m_spell; // If the spell is not ready to use yet, back out and continue waiting for the cooldown if (spellSlot.m_readyToUse) { // Toggle the aiming indicator corresponding to the spell m_aimController.IndicatorToggle(boundSpell.m_indicatorType); // If the spell is already active, turn it off. Otherwise, activate it if (m_currentSpellSlot != null && boundSpell == m_currentSpellSlot.m_spell) { m_currentSpellSlot = null; m_currentSpellIdx = -1; } else { m_currentSpellSlot = spellSlot; m_currentSpellIdx = _slotIdx; } // TODO: Update the UI indicator in the HUD to show the selected spell directly or through an event // ... } }
//--- Unity Methods ---// private void Awake() { // Init the private variables m_aimController = FindObjectOfType <AimController>(); m_currentSpellSlot = null; m_currentSpellIdx = -1; // Init the spell slots InitSpellSlots(); }