using System; using UnityEngine; /// /// Used on vulnerable trigger zones for ships. /// public class HitDetection : MonoBehaviour { [SerializeField] private TackleKind tackleKind; public Action TackledResponse; public Action TacklingResponse; [SerializeField] private HitKind hitKind = HitKind.IncomingNormal; public Action HitResponse; //ID of Owner GameObject of this hit detecting zone [HideInInspector] public int OwnerId = 0; void Awake() { OwnerId = transform.parent.gameObject.GetInstanceID(); } /// /// Invokes the fitting tackle response on trigger entered. /// /// void OnTriggerEnter(Collider collider) { if (!(collider.tag == "Spike" || collider.tag == "Bumper" || collider.tag == "Vulnerable")) { return; } switch (collider.tag) { case "Spike": // Critical for weak spots TackledResponse.Invoke(tackleKind, collider); break; case "Bumper": // Always normal tackle TackledResponse.Invoke(TackleKind.IncomingNormal, collider); break; case "Vulnerable": if (tackleKind == TackleKind.OutgoingCritical || tackleKind == TackleKind.OutgoingNormal) TacklingResponse.Invoke(); break; } } public void RegisterHit(ProjectileDamage damage) { HitResponse(hitKind, damage); } } public enum TackleKind { IncomingCritical, IncomingNormal, OutgoingCritical, OutgoingNormal } public enum HitKind { IncomingCritical, IncomingNormal } public struct ProjectileDamage { public float DamageValue; public float ImpactMagnitude; public Vector3 ImpactPoint; public Vector3 ImpactDirection; }