mercredi 31 mars 2021

Having troubles with if/else statement in condition with powerups

I'm new at Unity and programming. I'm working on a top down shooter game where the player can pickup powerups. I have no problems with picking up(colliding) with the powerups(gameObjects) and actually giving it a certain powerup. I gave every powerup a different kind of tag. But the thing is, that my world contains ground of lava which deals damage to the player. I can also make that work. But the problem now is that when I pickup a certain powerup, in this case its a fire powerup, I want the player to be immune to damage. Whatever I try I just can't make it work. I'm pretty sure I understand the if/else statement but it seems like I'm making a mistake somewhere but I can't find out where. Please help me out :(

HERE ARE SOME IMPORTANT INFO ABOUT THE SCRIPT:

public bool onLava = false;

public bool nuke = false;

PlayerHealthManager healthScript;

Void OnTriggerEnter(Collider other) {
//Fire Powerup//
//This code makes sure that I collide with the powerupFire object//
if(other.gameObject.tag == "Fire") {
powerupFire = true;
Destroy(other.gameObject);
if(powerupFire == true) {
//I think here should be the code which make me immune to lava//
}
}

//This code makes sure that I collide with the lava object//
//Lava//
if(other.gameObject.tag == "Lava"){
onLava = true;
if(onLava == true){
healthScript.currentHealth -= (int)healthUp;
health.Script.healthBar.SetHealth(healthScript.currentHealth);
}
//I thought this, (the else/if statement), would make sure it will check if "powerupFire == true"
and if it is true that it would set "onLava" on false which result in not running the previous if
statement but I guess I'm completley wrong in that because it's not working and it's not even
checking if the "powerupFire == true"//

else if (powerupFire == true) {
onLava = false;
}
}
}

Aucun commentaire:

Enregistrer un commentaire