Having trouble with a bool that wont return to false.
Firstly I am activating an ability with a function attached to a UI button (For Example Purrincess):
public void AvtivateAbility()
{
//abilityActive = true; // Setting the players abilty to active;
switch (chosenCharacterString) // Checking to see what character the player is playing as so the right ability can be activated.
{
case "Eddie Feathers": // Activate Eddie Feathers ability.
//abilityActiveTimerNeeded = true;
EddieFeathersAbility();
break;
case "Bookiekins": // Activate Bookiekins ability.
BookiekinsAbility();
break;
case "Mr. Mango": // Activate Mr. Mango's ability.
MrMangosAbility();
break;
case "Duckypoo": // Activate Duckypoo's ability.
DuckypoosAbility();
break;
case "Purrincess": // Activate Purrincess' ability.
//abilityActiveTimerNeeded = true;
PurrincessAbility();
break;
case "Maurice": // Activate Maurice's ability.
MauriceAbility();
break;
case "Bowie": // Activate Bowie's ability.
BowieAbility();
break;
case "Smokebad": // Activate Smokebad's ability.
SmokebadAbility();
break;
}
abilityActiveTimerNeeded = true;
}
Then calling the purrincess funtion:
void PurrincessAbility()
{
Debug.Log(“Purrincess’ Ability”);
// Briefly spawns pink balloons, which are worth more points than all others.
if (abilityActiveTimerNeeded == true)
{
purrincessAbilityActive = !purrincessAbilityActive;
}
else
{
purrincessAbilityActive = !purrincessAbilityActive;
}
AbilityDisplayText.text = ("Pink Balloons, More Points!");
}
problem is that the bool “purrincessAbilityActive” never returns to false.
Here is the Ability function that sets the other variables if that helps:
public void AbilityDisplays()
{
if (abilityActiveTimerNeeded)
{
abilityTimer += Time.deltaTime;
iTween.ScaleTo(AbilityDisplayObject, new Vector2(1, 1), 0.5f);
abilityButton.GetComponent().interactable = false;
if (abilityTimer >= 10)
{
iTween.ScaleTo(AbilityDisplayObject, new Vector2(0, 0), 0.5f);
abilityTimer = 0;
abilityActiveTimerNeeded = false;
abilityCooling = true;
}
}
if (abilityActive)
{
iTween.ScaleTo(AbilityDisplayObject, new Vector2(1, 1), 0.5f);
abilityButton.GetComponent<Button>().interactable = false;
abilityActive = false;
abilityCooling = true;
}
if (abilityCooling)
{
abilityCoolDown -= Time.deltaTime;
abilityButtonText.text = Mathf.RoundToInt(abilityCoolDown).ToString();
abilityActive = false;
if (abilityCoolDown <= 0.0f)
{
abilityCoolDown = 10;
abilityCooling = false;
abilityButton.GetComponent<Button>().interactable = true;
}
}
else
{
abilityButtonText.text = "Activate Ability";
}
}