Add unity event

This commit is contained in:
Soulaha Balde 2022-10-29 15:02:18 -04:00
parent a2ad4a99d2
commit 54a2575703

View File

@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Events;
public class TriggerZone : MonoBehaviour public class TriggerZone : MonoBehaviour
{ {
@ -8,11 +9,15 @@ public class TriggerZone : MonoBehaviour
private Triggerable linkedObj; private Triggerable linkedObj;
[SerializeField] [SerializeField]
private bool onEnter = true, onStay = false, OnExit = false; private bool onEnter = true, onStay = false, OnExit = false;
public UnityEvent enterEvent;
public UnityEvent stayEvent;
public UnityEvent exitEvent;
// Start is called before the first frame update // Start is called before the first frame update
private void OnTriggerEnter(Collider other) { private void OnTriggerEnter(Collider other) {
if(!onEnter)return; if(!onEnter)return;
if(other.gameObject.tag.Equals("Player")){ if(other.gameObject.tag.Equals("Player")){
linkedObj.TriggerEvent(); linkedObj.TriggerEvent();
enterEvent?.Invoke();
} }
} }
@ -20,6 +25,7 @@ public class TriggerZone : MonoBehaviour
if(!onStay)return; if(!onStay)return;
if(other.gameObject.tag.Equals("Player")){ if(other.gameObject.tag.Equals("Player")){
linkedObj.TriggerEvent(); linkedObj.TriggerEvent();
stayEvent?.Invoke();
} }
} }
@ -27,6 +33,7 @@ public class TriggerZone : MonoBehaviour
if(!OnExit)return; if(!OnExit)return;
if(other.gameObject.tag.Equals("Player")){ if(other.gameObject.tag.Equals("Player")){
linkedObj.TriggerEvent(); linkedObj.TriggerEvent();
exitEvent?.Invoke();
} }
} }
} }