Skip to content
Snippets Groups Projects
Commit ca90edde authored by Bill Clinton's avatar Bill Clinton
Browse files

Merge branch 'feat/enemy-pet-take-damage' into 'main'

Add Weapon Mechanism to Hit Enemy Pet

See merge request !25
parents 080fde2d 5c968ff9
Branches
Tags
1 merge request!25Add Weapon Mechanism to Hit Enemy Pet
...@@ -57,6 +57,16 @@ public class DefaultGun : Weapons ...@@ -57,6 +57,16 @@ public class DefaultGun : Weapons
enemyHealth.TakeDamage(damagePerShot, shootHit.point); 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. // Set the second position of the line renderer to the point the raycast hit.
gunLine.SetPosition(1, shootHit.point); gunLine.SetPosition(1, shootHit.point);
} }
......
...@@ -46,6 +46,16 @@ public class Shotgun : Weapons ...@@ -46,6 +46,16 @@ public class Shotgun : Weapons
int finalDamage = Mathf.Max(10, Mathf.RoundToInt(damagePerShot - hit.distance/range*damagePerShot)); int finalDamage = Mathf.Max(10, Mathf.RoundToInt(damagePerShot - hit.distance/range*damagePerShot));
enemyHealth.TakeDamage(finalDamage, hit.point); 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);
}
} }
} }
} }
......
...@@ -53,6 +53,17 @@ public class Sword : Weapons ...@@ -53,6 +53,17 @@ public class Sword : Weapons
// ... the enemy should take damage. // ... the enemy should take damage.
enemyHealth.TakeDamage(damagePerShot, shootHit.point); 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);
}
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment