DespawnOnGameOverOrStartReplay.cs 880 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. using System.Collections;
  3. public class DespawnOnGameOverOrStartReplay : MonoBehaviour
  4. {
  5. void OnEnable()
  6. {
  7. NotificationCenter.AddListener(Destruct, NotificationType.StartReplay);
  8. NotificationCenter.AddListener(Destruct, NotificationType.GameOver);
  9. NotificationCenter.AddListener(Destruct, NotificationType.LevelEditorPause);
  10. }
  11. void OnDisable()
  12. {
  13. NotificationCenter.RemoveListener(Destruct, NotificationType.StartReplay);
  14. NotificationCenter.RemoveListener(Destruct, NotificationType.GameOver);
  15. NotificationCenter.RemoveListener(Destruct, NotificationType.LevelEditorPause);
  16. }
  17. void Destruct(Notification note)
  18. {
  19. PoolObject poolObject = GetComponent<PoolObject>();
  20. if (poolObject != null)
  21. {
  22. poolObject.Despawn();
  23. } else
  24. {
  25. AVDebug.LogWarning("Should we use a Pool for this object? - " + name);
  26. Destroy(gameObject);
  27. }
  28. }
  29. }