Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Fungus;
- [EventHandlerInfo("Custom",
- "Trigger2D Enter",
- "Fires when anything hits the target collider, and returns the object that hit")]
- [AddComponentMenu("")]
- public class Custom_EventHandler_Trigger2D : EventHandler
- {
- /*
- Raising the event:
- Fungus.FungusManager.Instance.EventDispatcher.Raise(new Custom_EventHandler_Trigger2D.Custom_EventHandlerEvent() { target = targetCollider });
- */
- public Collider2D target;
- [VariableProperty(typeof(GameObjectVariable))]
- public GameObjectVariable returnObj;
- public class Custom_EventHandlerEvent
- {
- public Collider2D hitObject;
- public Collider2D source;
- }
- protected EventDispatcher eventDispatcher;
- protected virtual void OnEnable()
- {
- eventDispatcher = FungusManager.Instance.EventDispatcher;
- eventDispatcher.AddListener<Custom_EventHandlerEvent>(OnCustom_EventHandlerEvent);
- }
- protected virtual void OnDisable()
- {
- eventDispatcher.RemoveListener<Custom_EventHandlerEvent>(OnCustom_EventHandlerEvent);
- eventDispatcher = null;
- }
- void OnCustom_EventHandlerEvent(Custom_EventHandlerEvent evt)
- {
- if (target == evt.source)
- {
- if (returnObj != null)
- {
- returnObj.Value = evt.hitObject.gameObject;
- }
- ExecuteBlock();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement