47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
/// <summary>
|
|
/// Used on vulnerable trigger zones for ships.
|
|
/// </summary>
|
|
public class TackleDetection : MonoBehaviour
|
|
{
|
|
[SerializeField] private TackleKind tackleKind;
|
|
public Action<TackleKind, Collider> TackledResponse;
|
|
public Action TacklingResponse;
|
|
|
|
/// <summary>
|
|
/// Invokes the fitting tackle response on trigger entered.
|
|
/// </summary>
|
|
/// <param name="collider"></param>
|
|
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 enum TackleKind { IncomingCritical, IncomingNormal, OutgoingCritical, OutgoingNormal } |