My modification for Damage Collidor

I found a Bug that the Defender keep shooting for the enemy lan even if the enemy passed by . because the enemy is not destroyed and its location in the same Y-axis for the defender.

so if you didnt but a defender for lan 1 for example and the enemy passed away from the screen , then you put a defender later in the same lan , the defender keep shooting even the enemy spawner didnt spawn new enemy .

So to fix this , i make the damage collidor to destroy the enemy after reduce the player health.

private void OnTriggerEnter2D(Collider2D collision)
{

    GameObject attacker = collision.gameObject;

    if (attacker.GetComponent<Attacker>())
    {
        if (playerHealth.GetPlayerHealth() > 0)
        {
            playerHealth.DecreaseHealth(damage);
            Destroy(attacker.gameObject);
        }
        else
        {
            return;
        }
       
        

       
    }
    
}

another way is to make the defeneder only shoot if the X position of enemy is greater than the x position of the defender ( the Enemy position in the right side of the Defender and Both are in the same Y-position)

thanks.

Privacy & Terms