Exemplo n.º 1
0
    public void TakeDamage(int damage = 1, RhythmGrade grade = RhythmGrade.Miss, Transform attacker = null, float MissMultiplier = 1)
    {
        if (Time.time - lastDamagedTime <= InvincibilityTime || movementMachine.CurrentState is PlayerSuperState)
        {
            return;
        }


        lastDamagedTime = Time.time;
        _hurtLerper.LerpValue(true);
        CurrentHP -= damage;
        if (CurrentHP <= 0)
        {
            Die();
        }
        else
        {
            if (attacker)
            {
                Vector3 toAttacker = attacker.position - transform.position;
                toAttacker.y = 0;
                toAttacker   = toAttacker.normalized;
                toAttacker   = characterTransform.InverseTransformDirection(toAttacker);
                CharacterAnimator.SetFloat("DamageDirectionX", toAttacker.x * -1f);
                CharacterAnimator.SetFloat("DamageDirectionY", toAttacker.z * -1f);
            }
            movementMachine.TransitionTo <PlayerKnockBackState>();
        }
        HUDManager.Instance.UpdatePlayerHPUI(MaxHP, currentHP);
    }
Exemplo n.º 2
0
    public void TakeDamage(int damage = 1, RhythmGrade grade = RhythmGrade.Miss, Transform attacker = null, float MissMultiplier = 1)
    {
        if (_hurtLerper)
        {
            _hurtLerper.LerpValue(true);
        }

        if (grade == RhythmGrade.Miss && MissMultiplier == 0)
        {
            return;
        }

        Hp -= grade == RhythmGrade.Miss ? damage * MissMultiplier : damage;
        OnDamage?.Invoke();
        if (Hp <= 0)
        {
            if ((int)grade > 0)
            {
                PopUpPointsHandler.Instance.OnEnemyHitSpawn(transform.position, grade);
            }
            Die();
        }
        else if (!(Machine.CurrentState is AiCoreAttackState))
        {
            if (CurrentSlot.playerIndex >= 0 && CurrentSlot.playerIndex <= 3)
            {
                Machine.GetState <AiWalking>().shouldFreeSlot = false;
            }

            if ((int)grade > (int)GradeRequiredToKnockback)
            {
                if (EnemyType != Enemy.shooterAi)
                {
                    Machine.GetState <AiKnockbackState>().TriggerHeavyKnockBack = true;
                }
            }
            if (EnemyType == Enemy.basicAi)
            {
                Machine.TransitionTo <AiKnockbackState>();
            }
            if ((int)grade > 0)
            {
                PopUpPointsHandler.Instance.OnEnemyHitSpawn(transform.position, grade);
            }
        }
    }