I’m following the Brackeys tutorial for 2D combat in my own game, but I’m getting a compiler error with a Collider2D array.
Here’s the code that’s causing the issue.
void Attack()
{
animator.SetTrigger("Attack");
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
foreach (Collider2D enemy in hitEnemies)
{
Debug.Log("We hit " = enemy.name);
}
}
It seems like Unity isn’t recognizing Collider2D hitEnemies as a local variable, even though Visual Studio calls it that when I hover my mouse over it. This is frustrating, since nothing I can think to do seems to work, and I don’t really understand the code I’m working with.
Is there something I’m missing? Or should I give up and find a different tutorial?
Thanks!