1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 07:08:51 -05:00
UDRIGEEKCup2024/Assets/Scripts/OnColliderTrigger.cs
2024-04-17 12:30:02 -04:00

48 lines
1.5 KiB
C#

using System.Collections.Generic;
using UnityAtoms.BaseAtoms;
using UnityEngine;
using UnityEngine.Events;
using UnityAtoms.Tags;
namespace MAVRIC.GEEKCup
{
[RequireComponent(typeof(Collider))]
public class OnColliderTrigger : MonoBehaviour
{
public bool invertResult = false;
// TODO: Update this to use a UnityAtoms BoolReference
[SerializeField] private UnityEvent<bool> onTrigger;
[SerializeField] private LayerMask layerMask = 1 >> 0;
[SerializeField] private List<StringConstant> tagsMask = new ();
private void OnTriggerEnter(Collider other)
{
// if ((1 << other.gameObject.layer & layerMask) == 0) return;
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
Debug.Log($"HasValidTags: {hasValidTags}");
if (hasValidTags)
{
var result = invertResult ? false : true;
Debug.Log(result);
onTrigger?.Invoke(result);
}
}
private void OnTriggerExit(Collider other)
{
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
Debug.Log($"HasValidTags: {hasValidTags}");
if (hasValidTags)
{
var result = invertResult ? true : false;
Debug.Log($"Result: {result}");
onTrigger?.Invoke(result);
}
}
}
}