using System.Collections; using UnityEngine; public class Hitbox : MonoBehaviour { public float damage; public GameObject bloodVFXPrefab; private bool hasHit; void OnEnable() { hasHit = false; } void OnTriggerEnter(Collider other) { if (hasHit) return; Hurtbox hurtbox = other.GetComponent(); if (hurtbox == null) return; TeamMember attacker = GetComponentInParent(); TeamMember target = other.GetComponentInParent(); if (attacker == null || target == null) return; if (attacker.CurrentTeam == target.CurrentTeam) return; Health health = other.GetComponentInParent(); if (health != null) { hasHit = true; health.TakeDamage(damage, hurtbox.bodyPart); // CAMERA SHAKE ONLY WHEN HUMAN-CONTROLLED PLAYER HITS ENEMY if (attacker.CurrentControlType == TeamMember.ControlType.HumanControlled && CameraShakeNew.Instance != null) { CameraShakeNew.Instance.Shake(0.8f); } // Calculate direction Vector3 dir = attacker.transform.forward; dir.y = 0; if (dir.sqrMagnitude > 0.001f) dir.Normalize(); // Apply knockback health.ApplyKnockback(dir); // BLOOD EFFECT Vector3 hitPoint = other.ClosestPoint(transform.position); if (bloodVFXPrefab != null) { GameObject vfx = Instantiate(bloodVFXPrefab, hitPoint, Quaternion.identity); Vector3 vfxDir = other.transform.position - transform.position; if (vfxDir.sqrMagnitude > 0.001f) vfx.transform.forward = vfxDir.normalized; } if (AudioManager.Instance != null) { AudioManager.Instance.PlaySFX("Hit"); } } IEnumerator HitStop(float duration) { Time.timeScale = 0f; yield return new WaitForSecondsRealtime(duration); Time.timeScale = 1f; } } }