added headshots and enemy's shooting

This commit is contained in:
2026-02-18 00:40:22 +00:00
parent 27f2931ce1
commit e1df65bce2
6 changed files with 554 additions and 57 deletions

View File

@@ -209,9 +209,20 @@ public class SimpleGun : MonoBehaviour
Debug.Log($"Hit: {hit.transform.name}");
SpawnImpactEffect(hit.point, hit.normal);
EnemyHealth enemy = hit.transform.GetComponent<EnemyHealth>();
if (enemy != null)
enemy.TakeDamage(damage);
// Head hitbox = one shot kill
EnemyHeadHitbox head = hit.transform.GetComponent<EnemyHeadHitbox>();
if (head != null && head.enemyHealth != null)
{
Debug.Log("HEADSHOT! Instakill.");
head.enemyHealth.TakeDamage(head.enemyHealth.maxHealth * 10f);
}
else
{
// Body shot — check the hit object AND walk up to parent for EnemyHealth
EnemyHealth enemy = hit.transform.GetComponentInParent<EnemyHealth>();
if (enemy != null)
enemy.TakeDamage(damage);
}
}
}