44 lines
900 B
C#
44 lines
900 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EventTrigger : MonoBehaviour
|
|
{
|
|
public UnityEngine.Events.UnityEvent Action;
|
|
|
|
public bool triggerEventAtStart;
|
|
public bool doEventOnce;
|
|
private bool canInvokeEvent = true;
|
|
|
|
//public delegate void OnActionHappened();
|
|
//public event OnActionHappened onActionHappened;
|
|
|
|
private void Start()
|
|
{
|
|
if (triggerEventAtStart)
|
|
{
|
|
Invoke();
|
|
}
|
|
}
|
|
|
|
public void Invoke()
|
|
{
|
|
if (canInvokeEvent)
|
|
{
|
|
Action.Invoke();
|
|
print("Event invoked: " + gameObject.name);
|
|
if (doEventOnce)
|
|
{
|
|
canInvokeEvent = false;
|
|
//gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void ResetEvent()
|
|
{
|
|
canInvokeEvent = true;
|
|
}
|
|
}
|