コード例 #1
0
    public IEnumerator DelayedDamage(object[] args)
    {
        float delayTime = (float)args[0];

        yield return(new WaitForSeconds(delayTime)); // lmao this will be fine

        Player       player         = (Player)args[1];
        MeleeHandler m_meleeHandler = (MeleeHandler)args[2];

        float distanceFromPlayer = (player.transform.position - transform.position).magnitude;

        if (distanceFromPlayer - m_meleeHandler.GetAttackRange() <= 0f) // Check if in range BEFORE appling damage
        {
            player.m_healthHandler.Damage(m_meleeHandler.GetMeleeDamage());
            StartCoroutine(player.m_audioHandler.PlayDamageSound());
            StartCoroutine(player.m_healthHandler.ApplyDamageEffect(player.GetComponent <SpriteRenderer>()));
            player.m_movementHandler.Knockback(1000f, (player.transform.position - transform.position), player.GetComponent <Rigidbody2D>());
        }
    }
コード例 #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;
        }
    }