Having a small problem with the player getting a "free hit" before they die
I built a 2D shooter and everything works as I want it to, The players shields go down to zero after being hit, and then the health gets taken. when the player gets down to zero health, they seem to have an extra hit, where they have 0 health and 0 shields, but still haven't died. Here is the portion of my script that deals with taking damage
//if it is a enemy entity
else if (other.tag == "EnemyShip" || other.tag == "EnemyProjectile")
{
//shakes the camera
CameraShake.shake = true;
//sets the upgraded weapon to be downgraded
WeaponDowngrade();
//runs a check to see if the player has shields
if (curShields > 0)
{
//plays the power up sound effect
AudioSource.PlayClipAtPoint(ShieldHit, transform.position);
//takes away some of the player shields
ModShields(-5);
}
//if there is no shields and the player still has health
else if (curHealth > 0)
{
//plays the power up sound effect
AudioSource.PlayClipAtPoint(ShipHitnoshield, transform.position);
//take away some of the player health
ModHealth(-1);
}
//if the player has no health left
else if(curHealth == 0)
{
//plays the explosion audio
AudioSource.PlayClipAtPoint(BlowUp, transform.position);
//take away a life
ModLives(-1);
//reset the players health and shields
ResetPlayer();
}
}
Is there something simple that I seem to be missing?
How it is set up, is the player ship takes damage on his shields before health damage. The shields work, counting down from 100 to zero when taking damage. Then the health starts counting down from there. I should probably set the curHealth if its == to one and takes damage, then they lose a life.
Your answer
Follow this Question
Related Questions
Health bar/damage script not working. Please help. 0 Answers
Tool Durability if Hit any Collider 1 Answer
My health potion worked and now it doesn't. 1 Answer
Check if position is inside a collider 5 Answers
Spawning with trigger 2 Answers