0
\$\begingroup\$

I am currently working on a game which should be your basic RPG style and in this game I am using an Ability system based on ScriptableObjects. Each Ability has its own ParticleSystem (prefab) and AudioSource.

Basically all Ability.asset files are added to a list of Abilities. Using PageUp/Down buttons the player equips the next/previous Ability of the List.

When "Fire1" is pressed the ability is then cast which works just fine before equipping the next Ability. Then, no matter how many times I press "Fire1" no Ability is cast unless I click out of game-view and inside of it again. However in the Inspector everything seems OK.

Here's my code:

void Update ()
{
    abilityCount = AbilitySystem.Instance.allAbilities.Count - 1;
    abilityCooldown -= Time.deltaTime;
    if(Input.GetButtonDown("Fire1") && abilityCooldown <= 0f)
    {
        Shoot();
        abilityCooldown = 1f / castingSpeed;
    }

    if (Input.GetKeyDown(KeyCode.PageDown))
    {
        abilityIndex--;
        if (abilityIndex < 0)
        {
            abilityIndex = abilityCount;
        }
        currentAbility = AbilitySystem.Instance.allAbilities[abilityIndex];
        UpdateAbilityStats();
    }

    if (Input.GetKeyDown(KeyCode.PageUp))
    {
        abilityIndex++;
        if (abilityIndex > abilityCount)
        {
            abilityIndex = 0;
        }
        currentAbility = AbilitySystem.Instance.allAbilities[abilityIndex];
        UpdateAbilityStats();
    }

}

void UpdateAbilityStats()
{
    abilityDamage = currentAbility.abilityDamage;
    abilityRange = currentAbility.abilityRange;
    abilityCooldown = currentAbility.abilityCooldown;
    particles = currentAbility.Particles;
    particlesOnTarget = currentAbility.onTargetParticles;
}
\$\endgroup\$
5
  • 1
    \$\begingroup\$ My guess is castingSpeed becomes 0f and you get float.PositiveInfinity on abilityCooldown, then no matter what you subtract to that, it should never change. \$\endgroup\$
    – Alakanu
    Oct 16, 2017 at 16:19
  • \$\begingroup\$ @Alakanu how can I be so stupid, man you were absolutely right. Thanks. \$\endgroup\$
    – Valamorde
    Oct 16, 2017 at 16:50
  • \$\begingroup\$ @Alakanu that sounds like it's worth posting as an answer so it can be marked Accepted. \$\endgroup\$
    – DMGregory
    Oct 16, 2017 at 17:38
  • \$\begingroup\$ cheers, glad to help out \$\endgroup\$
    – Alakanu
    Oct 17, 2017 at 10:09
  • \$\begingroup\$ I added the answer, please accept it if it solved your problem :) \$\endgroup\$
    – Alakanu
    Oct 20, 2017 at 9:44

1 Answer 1

1
\$\begingroup\$

castingSpeed for some ability is 0f and abilityCooldown becomes float.PositiveInfinity, then no matter what you subtract to that, it will never become <= 0 so the if condition is never satisfied.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .