using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class combat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Attack();
}
}
void Attack()
{
animator.SetTrigger("Attack");
Collider2D[] hitEnemies = Physics2D.OverlabCircleAll(attackPoint.position, attackRange, enemyLayers);
forceach(Collider2D enemy in hitEnemies);
{
Debug.Log("We hit " + enemyLayers.name);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
see line #29 forceach(Collider2D enemy in hitEnemies);
There are two problems with it: “forceach” is not spelled correctly. Next, there’s a semi-colon at the end.
It should be written like so: foreach(Collider2D enemy in hitEnemies)