private void CastWithCost(GameObject caster, GameObject spell, bool movesWithCaster)
    {
        StatsHandler casterStats = caster.GetComponent <StatsHandler>();

        //check for cooldown
        if (Time.time >= nextCast)
        {
            nextCast = Time.time + cooldownTime;//set nup next time for next cast

            //check if caster has enough mana and cast if they do, cast the spell
            if (casterStats.GetMana() >= manaCost)
            {
                //remove mana then cast
                casterStats.ChangeMana(-manaCost);
                InstatiateSpell(caster, spell, movesWithCaster);
            }
            else if (isBoodmagic && casterStats.GetHealth() + casterStats.GetMana() >= manaCost)
            {
                //remove mana and health then cast
                casterStats.ChangeHealth(-(manaCost - casterStats.GetMana()));//minus the extra needed
                casterStats.ChangeMana(-casterStats.GetMana());
                InstatiateSpell(caster, spell, movesWithCaster);
            }
        }
    }
Exemple #2
0
    void Update()  //called when the component is disabled or set to be destroyed
    {
        if (casterStats.GetMana() == 0)
        {
            Destroy(gameObject);
        }

        casterStats.ChangeMana(-manaPerSec * Time.deltaTime);
    }