Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EventExample : MonoBehaviour
- {
- public delegate void ExampleEventHandler();
- public static event ExampleEventHandler OneDayPassed;
- public static void NextTurn()
- {
- // do stuff then send event
- if (OneDayPassed != null)
- OneDayPassed();
- }
- }
- public class EntityWatcher: MonoBehaviour
- {
- void Start()
- {
- EventExample.OneDayPassed += this.PrepareNextDay;
- }
- public void PrepareNextDay()
- {
- // Do other stuff that happen after the day is done
- }
- }
- public UnityEvent whoa;
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Events;
- public class BigScript:MonoBehaviour
- {
- [Header("Here's a cool event! Drag anything here!")]
- public UnityEvent whoa;
- }
- public class BigScript:MonoBehaviour
- {
- [Header("Here's a cool event! Drag anything here!")]
- public UnityEvent whoa;
- private void YourFunction()
- {
- whoa.Invoke();
- }
- whoa.AddListener(ScreenMaybeChanged);
- ...
- using UnityEngine.Events;
- // example, function has one float argument:
- // ADD THIS at the top of the file:
- [System.Serializable]
- public class _UnityEventFloat:UnityEvent<float> {}
- public class SimpleFingerResize : MonoBehaviour
- {
- public _UnityEventFloat changedLength;
- public _UnityEventFloat changedHeight;
- ... and then ...
- void ProcessValues(float v)
- {
- ....
- if (changedLength != null) changedLength.Invoke(1.4455f);
- }
- }
Add Comment
Please, Sign In to add comment