Files
CartoonFPS/Assets/Scripts/State.cs
2025-08-06 23:18:38 +01:00

39 lines
1.0 KiB
C#

using System;
using UnityEngine;
public class State
{
// These 'Action' delegates will hold references to methods for
// entering, exiting, and executing the state's main logic.
public Action ActiveAction, OnEnterAction, OnExitAction;
// The constructor assigns the methods passed in to the Action delegates.
public State(Action active, Action onEnter, Action onExit)
{
ActiveAction = active;
OnEnterAction = onEnter;
OnExitAction = onExit;
}
// Executes the state's main logic, if it exists.
public void Execute()
{
// Checks that the Action is not null before trying to run it.
if (ActiveAction != null)
ActiveAction.Invoke();
}
// Executes the state's entry logic, if it exists.
public void OnEnter()
{
if (OnEnterAction != null)
OnEnterAction.Invoke();
}
// Executes the state's exit logic, if it exists.
public void OnExit()
{
if (OnExitAction != null)
OnExitAction.Invoke();
}
}