So i’m new to delegates and i need to remove a specific item based on wether it returns true or false.
I am using the pub sub pattern.
I’m not even sure if i can call it an instance, i’m that new to it.
using UnityEngine;
public class Publisher : MonoBehaviour
{
private delegate bool Delegate();
Delegate del;
public void AddSubscriber(Subscriber new_sub)
{
del += new_sub.Trigger;
}
public void RemoveSubscriber(Subscriber sub)
{
del -= sub.Trigger;
}
public void Publish()
{
del.Invoke();
}
}
using UnityEngine;
public class Subscriber : MonoBehaviour
{
protected int days;
public bool Trigger()
{
if (days > 0)
{
days--;
return false;
}
else
{
return true;
}
}
}
So if Trigger returns false it would have to get removed out of the del delegate.
Thanks in advance.