using UnityEngine;

public class Subscriber : MonoBehaviour
{
    // We subscribe functions to action events in the Publisher class
    private void OnEnable()
    {
        Publisher.eventWithNoArguments += LogEventWithNoArguments;
        Publisher.eventWithIntArgument += LogEventWithIntArgument;
    }

    // We unsubscribe subscribe functions from action events in the Publisher class
    // If you do not unsubscribe and the subscriber class instance is destroyed, invoking the
    // Publisher class events will throw an error!
    private void OnDisable()
    {
        Publisher.eventWithNoArguments -= LogEventWithNoArguments;
        Publisher.eventWithIntArgument -= LogEventWithIntArgument;
    }

    private void LogEventWithNoArguments()
    {
        Debug.Log("eventWithNoArguments has been invoked");
    }

    private void LogEventWithIntArgument(int number)
    {
        Debug.Log($"eventWithIntArgument has been invoked with value {number}");
    }
}
