diff --git a/Assets/Scripts/Weapons/DefaultGun.cs b/Assets/Scripts/Weapons/DefaultGun.cs index 051b60935c60be9e667bdc5559fb3afb5b60bd99..dd275d14d6710fff962ff96e9961f3a60cc2e3c4 100644 --- a/Assets/Scripts/Weapons/DefaultGun.cs +++ b/Assets/Scripts/Weapons/DefaultGun.cs @@ -57,6 +57,16 @@ public class DefaultGun : Weapons enemyHealth.TakeDamage(damagePerShot, shootHit.point); } + // Try and find an EnemyPetHealth script on the gameobject hit. + EnemyPetHealth enemyPetHealth = shootHit.collider.GetComponent<EnemyPetHealth>(); + + // If the EnemyPetHealth component exist... + if (enemyPetHealth != null) + { + // ... the enemy pet should take damage. + enemyPetHealth.TakeDamage(damagePerShot, shootHit.point); + } + // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } diff --git a/Assets/Scripts/Weapons/Shotgun.cs b/Assets/Scripts/Weapons/Shotgun.cs index 3c556268d35dab5809ac9545b7f31f7f9ef5afe3..923b41bb56ca42f3466b0f200dc9ff267f0d1f75 100644 --- a/Assets/Scripts/Weapons/Shotgun.cs +++ b/Assets/Scripts/Weapons/Shotgun.cs @@ -46,6 +46,16 @@ public class Shotgun : Weapons int finalDamage = Mathf.Max(10, Mathf.RoundToInt(damagePerShot - hit.distance/range*damagePerShot)); enemyHealth.TakeDamage(finalDamage, hit.point); } + + EnemyPetHealth enemyPetHealth = hit.collider.GetComponent<EnemyPetHealth>(); + // If the EnemyPetHealth component exist... + if (enemyPetHealth != null) + { + // ... the enemy pet should take damage. + // Damage is lower the farther the enemy pet is. + int finalDamage = Mathf.Max(10, Mathf.RoundToInt(damagePerShot - hit.distance / range * damagePerShot)); + enemyPetHealth.TakeDamage(finalDamage, hit.point); + } } } } diff --git a/Assets/Scripts/Weapons/Sword.cs b/Assets/Scripts/Weapons/Sword.cs index 1fe2136accff8e32afc1c6ee7fa5ec1686aaf158..4a3c4b20f2e67547a66178c436b59b6e23463c57 100644 --- a/Assets/Scripts/Weapons/Sword.cs +++ b/Assets/Scripts/Weapons/Sword.cs @@ -53,6 +53,17 @@ public class Sword : Weapons // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot, shootHit.point); } + + // Try and find an EnemyPetHealth script on the gameobject hit. + EnemyPetHealth enemyPetHealth = shootHit.collider.GetComponent<EnemyPetHealth>(); + + // If the EnemyPetHealth component exist... + if (enemyPetHealth != null) + { + // ... the enemy pet should take damage. + Debug.Log("SWORDD"); + enemyPetHealth.TakeDamage(damagePerShot, shootHit.point); + } } } }