Checkpoint
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Checkpoint : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
public static Checkpoint Active { get; private set; }
|
||||
|
||||
[SerializeField] private bool _isDefault;
|
||||
[SerializeField] private UnityEvent _onActivated;
|
||||
[SerializeField] private UnityEvent _onDisable;
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
|
||||
if (Active)
|
||||
Active.Disable();
|
||||
|
||||
Active = this;
|
||||
_onActivated?.Invoke();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public void Disable()
|
||||
{
|
||||
|
||||
if (Active == this)
|
||||
{
|
||||
Active = null;
|
||||
_onDisable?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (_isDefault)
|
||||
Activate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user