Esempio n. 1
0
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.CompareTag("NPC"))
            {
                var npcManager = other.gameObject.GetComponent <NPCManager>();
                if (npcManager.IsChasing())
                {
                    npcManager.StartPunching();
                }
            }

            if (other.gameObject.CompareTag("Hand") && !invincible)
            {
                var npcManager = other.transform.root.gameObject.GetComponent <NPCManager>();
                if (npcManager.IsChasing() && npcManager._npcData.Punching && !Indestructibles.PlayerData.IsKnockedOut)
                {
                    npcManager.OnPlayerHit();
                    // Play a random grunt sound
                    if (gruntSounds.Length > 0)
                    {
                        _audioSource.PlayOneShot(gruntSounds[Random.Range(0, gruntSounds.Length - 1)]);
                    }

                    // Player is dead
                    if (--Indestructibles.PlayerData.HealthPoints <= 0)
                    {
                        Indestructibles.PlayerData.IsKnockedOut = true;
                        _animator.SetTrigger(Animator.StringToHash("Knocked Out"));
                        gameManager.OnPlayerDeath();
                        Indestructibles.PlayerData.IntoxicationLevel = 0.0f;
                        ClearEffects();
                        CancelInvoke(nameof(AddPoint));
                    }
                    else
                    {
                        // Player got hit but is not dead
                        var direction = (transform.position - npcManager.transform.position).normalized;

                        // Temporarily disable root motion to add a push force
                        Indestructibles.PlayerAnimator.applyRootMotion = false;
                        _rigidbody.AddForce(direction * 5.0f, ForceMode.Impulse);
                        Invoke(nameof(EnableRootMotion), 0.5f);

                        invincible = true;
                        Invoke(nameof(DisableInvincible), 2.0f);

                        // Flicker effect
                        InvokeRepeating(nameof(FlickerModel), 0.0f, 0.125f);
                        Invoke(nameof(StopFlicker), 2.0f);

                        // Sober up
                        if (onHitSoberUp)
                        {
                            Indestructibles.PlayerData.IntoxicationLevel -= 0.25f;
                            ClearEffects();
                        }
                    }
                }
                Indestructibles.UIManager.RefreshUI();
            }
        }