Sample02_ObservableTriggers.cs 709 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using UniRx.Triggers; // Triggers Namepsace
  3. using System;
  4. namespace UniRx.Examples
  5. {
  6. public class Sample02_ObservableTriggers : MonoBehaviour
  7. {
  8. void Start()
  9. {
  10. // Get the plain object
  11. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  12. // Add ObservableXxxTrigger for handle MonoBehaviour's event as Observable
  13. cube.AddComponent<ObservableUpdateTrigger>()
  14. .UpdateAsObservable()
  15. .SampleFrame(30)
  16. .Subscribe(x => Debug.Log("cube"), () => Debug.Log("destroy"));
  17. // destroy after 3 second:)
  18. GameObject.Destroy(cube, 3f);
  19. }
  20. }
  21. }