using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAttack : MonoBehaviour
{
    public Transform attackpoint;
    public float attackrange = 0.5f;
    public LayerMask enemylayers;

    void OnDrawGizmos()
    {
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(attackpoint.position, attackrange);
    }

    public void attack()
    {
        // detect enemy


        Collider[] hitenemies = Physics.OverlapSphere(attackpoint.position, attackrange, enemylayers);

        // damage

        foreach (Collider enemy in hitenemies)
        {
            //StartCoroutine(waitBeforeDestroy(enemy));
            Destroy(enemy.gameObject);
            if (enemy.gameObject.name == "Banana")
                enemy.gameObject.GetComponent<Animator>().SetBool("happy", false);
        }
    }

    IEnumerator waitBeforeDestroy(Collider enemy)
    {
        yield return new WaitForSeconds(.5f);
        Destroy(enemy.gameObject);
    }
}
