So my Problem is Currenty that i have a working healthsystem/health bar, but if i attack 1 enemy all the other ones get Damaged aswell.
this is my scripst so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthEnemy : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth;
public HealthBar healthBar;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
healthBar.SetMaxHealth(maxHealth);
}
void OnTriggerEnter(Collider _collision){
if(_collision.gameObject.tag==“projectilefriendly”)
{
TakeDamage(20);
}
void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
}
}
// Update is called once per frame
void Update()
{
if(currentHealth <= 0)
{
DestroyEntity();
}
void DestroyEntity()
{
Destroy(gameObject);
}
}
}