Beispiel #1
0
    // a method to handle melee enemy attack
    public void Attack()
    {
        anim.SetFloat("Speed", 0.0f);

        #region edited by :
        // Changed made by : Samuel Edsel Fernandez
        // Edited 23 mar 2019
        // Purpose :Make the AI detect which deretion he need to facing when attacking
        #endregion

        #region Comented
        //distance = Mathf.Abs(transform.position.x - player.transform.position.x);
        //if (distance > range)
        //{
        //    CurrState = EnemyState.CHASE;
        //    return;
        //}
        //else
        //{
        //    if (!entityAttack.IsAttacking)
        //    {
        //        entityAttack.Attack(Atk, range);
        //    }
        //}
        #endregion

        distance = transform.position.x - player.transform.position.x;

        #region Explanation
        //if distance is minus than the player is at left
        //The isFacingRight variable is flipped so if isFacingRight == true the enemy will facing left
        #endregion

        if (distance < 0 && isFacingRight == false && distance < range)
        {
            Debug.Log("Player at the left");
            Flip();
        }
        else if (distance > 0 && isFacingRight == true && distance < range)
        {
            Debug.Log("Player at the right");
            Flip();
        }

        if (Mathf.Abs(distance) > range)
        {
            CurrState = EnemyState.CHASE;
            return;
        }
        else
        {
            if (!entityAttack.IsAttacking)
            {
                entityAttack.Attack(Atk, range);
            }
        }
    }
Beispiel #2
0
 // a method to handle input for attacks
 public bool InputAttack()
 {
     if (!Input.GetKey(KeyCode.Tab))
     {
         if (Input.GetKeyDown("z"))
         {
             // Debug.Log("Weapon Type: " +  weapon.WeaponType);
             // Debug.Log("Attack Strength: " + atk);
             entityAttack.Attack(Atk, range);
         }
     }
     return(false);
 }