示例#1
0
    private void Attack()
    {
        // Is the character able to attack?
        if (m_meleeHandler.canMelee)
        {
            Collider2D[] m_collidedEnemies = m_meleeHandler.GetEnemiesInAttack(this);
            m_animatorController.ToggleTrigger(m_animTriggers.m_attackTriggerNames[0], true);

            if (m_collidedEnemies.Length != 0)
            {
                Player player = m_collidedEnemies[0].GetComponent <Player>();



                if (player != null)
                {
                    object[] args = new object[3] {
                        0.7f, player, m_meleeHandler
                    };
                    //Waits to deal the damage until the swinging frame of the animation and then deals the damage.
                    StartCoroutine("DelayedDamage", args);
                }

                m_meleeHandler.ResetCooldown();
            }
        }
        else
        {
            m_meleeHandler.meleeCooldownRemaining -= Time.deltaTime;
        }
    }
示例#2
0
    private void HandleCombatInput()
    {
        if (Input.GetKeyDown(ControlScheme.m_meleeKey))
        {
            // Is the player character able to attack?
            if (m_meleeHandler.canMelee)
            {
                m_animatorController.ToggleTrigger(m_animTriggers.m_attackTriggerNames[m_meleeAnimation], true);
                // Alternate between the 2 animations
                if (m_meleeAnimation == 0)
                {
                    ++m_meleeAnimation;
                }
                else
                {
                    --m_meleeAnimation;
                }

                StartCoroutine(m_audioHandler.PlayAttackSound());
                //Makes an array for all the colliders to be hit by the attack
                Collider2D[] m_collidedEnemies = m_meleeHandler.GetEnemiesInAttack(this);

                for (int i = 0; i < m_collidedEnemies.Length; i++)
                {
                    BaseCharacter enemy = m_collidedEnemies[i].GetComponent <BaseCharacter>();


                    //causes damage to every character that has been hit whilst applying a red affect and knockback.
                    enemy.m_healthHandler.Damage(m_meleeHandler.GetMeleeDamage());
                    StartCoroutine(enemy.m_healthHandler.ApplyDamageEffect(enemy.GetComponent <SpriteRenderer>()));
                    enemy.m_movementHandler.Knockback(1000f, (enemy.transform.position - transform.position), enemy.GetComponent <Rigidbody2D>());
                }

                m_meleeHandler.ResetCooldown();
            }
        }
        else // Cooldown is in effect
        {
            m_meleeHandler.meleeCooldownRemaining -= Time.deltaTime;
        }
    }