示例#1
0
 private void Awake()
 {
     playerAttacking       = GetComponentInChildren <PlayerAttacking>();
     playerInventory       = GetComponent <PlayerInventory>();
     playerManager         = GetComponent <PlayerManager>();
     playerStats           = GetComponent <PlayerStats>();
     uiManager             = FindObjectOfType <UIManager>();
     cameraHandler         = FindObjectOfType <CameraHandler>();
     weaponSlotManager     = GetComponentInChildren <WeaponSlotManager>();
     playerAnimatorManager = GetComponentInChildren <PlayerAnimatorManager>();
     playerFXManager       = GetComponentInChildren <PlayerFXManager>();
     blockingCollider      = GetComponentInChildren <BlockingCollider>();
 }
        private void OnTriggerEnter(Collider collision)
        {
            if (collision.tag == "Player")
            {
                PlayerStats      playerStats           = collision.GetComponent <PlayerStats>();
                CharacterManager enemyCharacterManager = collision.GetComponent <CharacterManager>();
                BlockingCollider shield = collision.transform.GetComponentInChildren <BlockingCollider>();

                if (enemyCharacterManager != null)
                {
                    if (enemyCharacterManager.isParrying)
                    {
                        // play animation
                        characterManager.GetComponentInChildren <AnimatorManager>().PlayTargetAnimation("Parried", true);
                        return;
                    }
                    else if (shield != null && enemyCharacterManager.isBlocking)
                    {
                        float physicalDamageAfterBlock =
                            currentWeaponDamage - (currentWeaponDamage * shield.blockingPhysicalDamageAbsorption) / 100;

                        if (playerStats != null)
                        {
                            playerStats.TakeDamage(Mathf.RoundToInt(physicalDamageAfterBlock), "Block Guard");
                            return;
                        }
                    }
                }
                if (playerStats != null)
                {
                    playerStats.TakeDamage(currentWeaponDamage);
                }
            }

            if (collision.tag == "Enemy")
            {
                EnemyStats       enemyStats            = collision.GetComponent <EnemyStats>();
                CharacterManager enemyCharacterManager = collision.GetComponent <CharacterManager>();
                BlockingCollider shield = collision.transform.GetComponentInChildren <BlockingCollider>();

                if (enemyCharacterManager != null)
                {
                    if (enemyCharacterManager.isParrying)
                    {
                        // play animation
                        characterManager.GetComponentInChildren <EnemyAnimatorManager>().PlayTargetAnimation("Parried", true);
                        return;
                    }
                    else if (shield != null && enemyCharacterManager.isBlocking)
                    {
                        float physicalDamageAfterBlock =
                            currentWeaponDamage - (currentWeaponDamage * shield.blockingPhysicalDamageAbsorption) / 100;

                        if (enemyStats != null)
                        {
                            enemyStats.TakeDamage(Mathf.RoundToInt(physicalDamageAfterBlock), "Block Guard");
                            return;
                        }
                    }
                }

                if (enemyStats != null)
                {
                    enemyStats.TakeDamage(currentWeaponDamage);
                }
            }

            if (collision.tag == "Hidden Wall")
            {
                HiddenWall hiddenWall = collision.GetComponent <HiddenWall>();

                hiddenWall.wallHasBeenHit = true;
            }
        }