Tanoda
Dana/CollisionEvents.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Linq;
5using UnityEngine;
7
8public class CollisionEvents : MonoBehaviour
9{
10 public bool inOrder = false;
11 public List<NamedCollisionEvents> collisions;
12
13 private int _orderCounter = 0;
14
15 void OnTriggerEnter(Collider other)
16 {
17 if (inOrder)
18 {
19 try
20 {
21 if (collisions[_orderCounter].colliderName == other.name)
22 {
23 collisions[_orderCounter].onTriggerEnter.Invoke();
24 _orderCounter++;
25 }
26 }
27 catch (Exception)
28 {
29 // finished
30 }
31 }
32 try
33 {
34 collisions.First(x => x.colliderName == other.name).onTriggerEnter.Invoke();
35 }
36 catch (Exception)
37 {
38 // ignored
39 }
40 }
41}
42[Serializable]
43public struct NamedCollisionEvents
44{
45 public string colliderName;
46 public UnityEvent onTriggerEnter;
47}
List< NamedCollisionEvents > collisions