Hello guys,
I thought that I would develop some droppable objects in my game like hp shields and special attacks that you get if the enemy random drops them… I decided to start adding them one by one as to avoid balancing issues. However no matter how I write the code the moment I place the Hpdrop prefab within the game I become either immortal or I keep getting healed every frame doesnt matter if I’m actually colliding with the hpdrop prefab.
What I am saying in my code is basically :
void OnTriggerEnter2D ()
{
if (GameObject.FindWithTag ("Enemy")) {
CurrentHealth -= 1;
}
if (GameObject.FindWithTag ("HealthDrop")) {
CurrentHealth += 1;
}
if (GameObject.FindWithTag ("Lightning")) {
StartCoroutine (Timer());
}
if(invulnPeriod > 0) {
invulnTimer = invulnPeriod;
gameObject.layer = 10;
}
}
Now the Lightning and the Enemy game objects work perfectly. If I get hit by lightning(this is only for the final lvl) I get destroyed after a 0.2 second CD (as my per my coroutine), the part also works perfectly if I collide with an enemy or an enemy attack, I lose 1 health. But the moment I add the droppablehp prefab everything goes on the fritz. Ive tried many ways to write the code such as using else statements and introducing a new coroutine to specifically handle the droppable health none of them worked properly like I said either I become immortal while the droppablehp object is in the game or I gain health every frame regardless of whether Im colliding with the object or not… Any help would be appreciated!