Skip to content

Instantly share code, notes, and snippets.

@rubit0
Created September 1, 2021 09:38
Show Gist options
  • Save rubit0/44a34becbfed8209817d34482485afee to your computer and use it in GitHub Desktop.
Save rubit0/44a34becbfed8209817d34482485afee to your computer and use it in GitHub Desktop.
Useful component to perform basic actions on Unity lifecycle events directly from the inspector ✨
using UnityEngine;
using UnityEngine.Events;
public class LifecycleEventsTrigger : MonoBehaviour
{
[SerializeField]
private UnityEvent onAwake;
[SerializeField]
private UnityEvent onStart;
[SerializeField]
private UnityEvent onEnable;
[SerializeField]
private UnityEvent onDisable;
[SerializeField]
private UnityEvent onDestroy;
[SerializeField]
private UnityEvent onBecameInvisible;
[SerializeField]
private UnityEvent onBecameVisible;
private void Awake()
{
onAwake?.Invoke();
}
private void Start()
{
onStart?.Invoke();
}
private void OnEnable()
{
onEnable?.Invoke();
}
private void OnDisable()
{
onDisable?.Invoke();
}
private void OnDestroy()
{
onDestroy?.Invoke();
}
private void OnBecameInvisible()
{
onBecameInvisible?.Invoke();
}
private void OnBecameVisible()
{
onBecameVisible?.Invoke();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment