Here is the code of the trigger of the event itself
public class ActivateEvent : MonoBehaviour { private bool activated; public Signal[] actionList; [HideInInspector] public int actionEventAmount; // Use this for initialization void Start() { activated = false; } void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag.Equals("Player") && !activated) { Activate(); } } public void Activate() { activated = true; for(int i=0;i<actionEventAmount;i++) { actionList[i].Invoke(); } } }
and here is the code for the Signal Class
public class Signal { public GameObject target; public string method; public string argType; public Signal() { } public Signal(System.Type argType) { this.argType = argType.FullName; } public void Invoke() { if (target != null && !string.IsNullOrEmpty(method)) target.SendMessage(method, SendMessageOptions.RequireReceiver); } public void Invoke(object value) { if (argType != null) { if (target != null && !string.IsNullOrEmpty(method)) { if (argType.Equals(value.GetType().FullName)) target.SendMessage(method, value, SendMessageOptions.RequireReceiver); else Debug.LogError("Incorrect parameter type, expected [" + argType + "], got [" + value.GetType().FullName + "]."); } } else Invoke(); } } public class SignalAttribute : System.Attribute { public string name; public SignalAttribute() { } public SignalAttribute(string name) { this.name = name; } }