mardi 29 mai 2018

IF statement - Unity c#

I don't understand why it isn't working. When I pick up the Shield Powerup, it turns canShield from false to true. But then, when I'm damaged, it is supposed to turn it back to false but it doesn't. It keeps true for the entire game.

public void Damage()
{
    if(canShield == true)
    {
        canShield = false;

        return;
    }

    _life--;


    if(_life < 1)
    {
        Destroy(this.gameObject);
        Instantiate (_explosionPrefab, transform.position, Quaternion.identity);
    }
}

Aucun commentaire:

Enregistrer un commentaire