// Update is called once per frame
    void Update()
    {
        /*
         * Enemy in combat mode will move to the target and attack auto
         */
        float distance = Vector3.Distance(target.position, transform.position);

        if (distance <= lookRadius)
        {
            // Enemy move to target direction
            agent.SetDestination(target.position);

            // if enemy is at shorter distance than stoppingDistance of the target of at least 0.2f
            if (distance <= agent.stoppingDistance + margin)
            {
                // Attack the target
                CharacterStatsBin targetStats = target.GetComponent <CharacterStatsBin>();
                if (targetStats != null)
                {
                    combat.Attack(targetStats);
                }

                // Face the target
                FaceTarget();
            }
        }
    }
 void PerformAttack()
 {
     Debug.Log("Call Player PerformAttack");
     if (focus != null)
     {
         CharacterStatsBin targetStats = focus.GetComponent <CharacterStatsBin>();
         combat.Attack(targetStats);
     }
 }
    // Coroutine to delay the damage for the animation
    IEnumerator DoDamage(CharacterStatsBin stats, float delay)
    {
        // wait animation delay
        yield return(new WaitForSeconds(delay));

        // apply damage
        stats.TakeDamage(myStats.Damage.GetValue());

        // if target is dead
        if (stats.CurrentHealth <= 0)
        {
            // then you are no more in combat after 2 secondes
            yield return(new WaitForSeconds(2));

            InCombat = true;
        }
    }
    public void Attack(CharacterStatsBin targetStats)
    {
        // if it's time to attack then attack
        if (attackCooldown <= 0f)
        {
            // delaying the animation
            StartCoroutine(DoDamage(targetStats, attackDelay));

            // start the attack animation
            OnAttack?.Invoke();

            // bigger is the attackspeed, smaller the cooldown is
            attackCooldown = 1f / attackSpeed;

            // still in combat
            InCombat       = true;
            lastAttackTime = Time.time;
        }
    }
    // move to combat !!!
    void AutoAttack()
    {
        float distance = Vector3.Distance(focus.transform.position, transform.position);

        if (distance <= radius)
        {
            // Attack the target
            CharacterStatsBin targetStats = focus.GetComponent <CharacterStatsBin>();
            if (targetStats != null)
            {
                //InvokeRepeating("PerformAttack", 1, PlayerManager.instance.PlayerStats.AttackSpeed.GetValue());
                combat.Attack(targetStats);
            }

            /*else
             * {
             *  CancelInvoke();
             * }*/
        }
    }
 private void Start()
 {
     myStats = GetComponent <CharacterStatsBin>();
 }