Exemplo n.º 1
0
    void Update()
    {
        // условие получил ли игрок урон
        if (isHit)
        {
            // запуск таймера неуязвимости
            postHitTime -= Time.deltaTime;

            // сброс таймера неуязвимости
            if (postHitTime <= 0)
            {
                postHitTime = 2;
                isHit       = false;
            }

            // Запуск анимации неуязвимости
            animator.SetBool("isHitAnim", isHit);
        }

        if (health <= 0)
        {
            isDeath = true;

            animator.SetBool("Death", isDeath);

            _inputs.isControlActive = false;

            postDeathTime -= Time.deltaTime;

            if (postDeathTime <= 0)
            {
                if (lives <= 0)
                {
                    LivesEvent?.Invoke();
                }
                else
                {
                    _respawn.RespawnPosition(_inputs.startPosition);

                    isDeath = false;

                    postDeathTime = 2;

                    animator.SetBool("Death", isDeath);

                    animator.SetInteger("Health", health);

                    _inputs.isControlActive = true;

                    health = 100;
                }
            }
        }
    }