Add Listener

using System.Collections;
using System.Collections.Generic;
using GK.Events.Runtime;
using UnityEngine;

namespace GK.Events.Demo
{
    public class Clock : MonoBehaviour
    {
        public GKEvent<float> onShowCurrentTime;

        void Update(){
            if (Time.time % 1 < 0.01f)
            {
                onShowCurrentTime.Invoke(Time.time);
            }
        }

        ////////////////////////////////////////////////////
        // Just use Add Listener like how you use UnityEvent
        ////////////////////////////////////////////////////
        
        void Awake(){
            onShowCurrentTime.AddListener(DebugCurrentTime);
        }

        void DebugCurrentTime(float time){
            Debug.Log("Current time: " + time);
        }
        
        ////////////////////////////////////////////////////
    }

}

Or use it with Lamda

using System.Collections;
using System.Collections.Generic;
using GK.Events.Runtime;
using UnityEngine;

namespace GK.Events.Demo
{
    public class Clock : MonoBehaviour
    {
        public GKEvent<float> onShowCurrentTime;

        void Update(){
            //Every 1 second, show the current time
            if (Time.time % 1 < 0.01f)
            {
                onShowCurrentTime.Invoke(Time.time);
            }
        }

        ////////////////////////////////////////////////////
        void Awake(){
            onShowCurrentTime.AddListener((time) => {
                Debug.Log("Current time: " + time);
            });
        }
        ////////////////////////////////////////////////////
    }

}

Last updated