Hi, in my RPG, I wanted to add keyboard controls for melee attacks. This code seems to work fine right now and the enemies are dying when I get in range and attack. Is this fine to use?
void Update()
{
foreach (Enemy enemy in enemies)
{
float distanceFromEnemy = Vector3.Distance(transform.position, enemy.transform.position);
if (distanceFromEnemy <= attackRadius)
{
if (Input.GetButtonDown("Fire1"))
{
enemy.TakeDamage(damage);
}
}
}
}