30 lines
663 B
C#
30 lines
663 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
public class CollisionDetector : MonoBehaviour
|
|
{
|
|
public List<string> tagsToDetect;
|
|
|
|
public Action<Collider> OnEnter;
|
|
public Action<Collider> OnExit;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if(tagsToDetect.Contains(other.tag) || tagsToDetect.Count == 0)
|
|
{
|
|
OnEnter?.Invoke(other);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if(tagsToDetect.Contains(other.tag) || tagsToDetect.Count == 0)
|
|
{
|
|
OnExit?.Invoke(other);
|
|
}
|
|
}
|
|
|
|
}
|