Esempio n. 1
0
        private void MeleeDamage(FPSWeapon weapon)
        {
            if (!mainCamera || !weapon)
            {
                return;
            }

            // Fire ray along player facing using weapon range
            RaycastHit hit;
            Ray        ray = new Ray(mainCamera.transform.position + mainCamera.transform.forward * 0.1f, mainCamera.transform.forward);

            if (Physics.SphereCast(ray, SphereCastRadius, out hit, weapon.Range - SphereCastRadius))
            {
                // Check if hit has an DaggerfallActionDoor component
                DaggerfallActionDoor actionDoor = hit.transform.gameObject.GetComponent <DaggerfallActionDoor>();
                if (actionDoor)
                {
                    actionDoor.AttemptBash();
                    return;
                }

                // Check if hit has an EnemyHealth - this should be done with Enemy tag in a real project
                EnemyHealth enemyHealth = hit.transform.gameObject.GetComponent <EnemyHealth>();
                if (enemyHealth)
                {
                    // Example: Play sound based on fake parry mechanics
                    if (Random.value < ChanceToBeParried)
                    {
                        // Parried
                        weapon.PlayParrySound();
                        return;
                    }
                    else
                    {
                        // Connected
                        weapon.PlayHitSound();
                        enemyHealth.RemoveHealth(player, Random.Range(weapon.MinDamage, weapon.MaxDamage), hit.point);
                    }
                }
            }
        }
        private void MeleeDamage(FPSWeapon weapon)
        {
            if (!mainCamera || !weapon)
                return;

            // Fire ray along player facing using weapon range
            RaycastHit hit;
            Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward);
            if (Physics.SphereCast(ray, SphereCastRadius, out hit, weapon.Range - SphereCastRadius))
            {
                // Check if hit has an DaggerfallActionDoor component
                DaggerfallActionDoor actionDoor = hit.transform.gameObject.GetComponent<DaggerfallActionDoor>();
                if (actionDoor)
                {
                    actionDoor.AttemptBash();
                    return;
                }

                // Check if hit has an EnemyHealth - this should be done with Enemy tag in a real project
                EnemyHealth enemyHealth = hit.transform.gameObject.GetComponent<EnemyHealth>();
                if (enemyHealth)
                {
                    // Example: Play sound based on fake parry mechanics
                    if (Random.value < ChanceToBeParried)
                    {
                        // Parried
                        weapon.PlayParrySound();
                        return;
                    }
                    else
                    {
                        // Connected
                        weapon.PlayHitSound();
                        enemyHealth.RemoveHealth(player, Random.Range(weapon.MinDamage, weapon.MaxDamage), hit.point);
                    }
                }
            }
        }