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;
}