1234567891011121314151617181920212223242526272829303132 |
- using UnityEngine;
- using System.Collections;
- public class DespawnOnGameOverOrStartReplay : MonoBehaviour
- {
- void OnEnable()
- {
- NotificationCenter.AddListener(Destruct, NotificationType.StartReplay);
- NotificationCenter.AddListener(Destruct, NotificationType.GameOver);
- NotificationCenter.AddListener(Destruct, NotificationType.LevelEditorPause);
- }
- void OnDisable()
- {
- NotificationCenter.RemoveListener(Destruct, NotificationType.StartReplay);
- NotificationCenter.RemoveListener(Destruct, NotificationType.GameOver);
- NotificationCenter.RemoveListener(Destruct, NotificationType.LevelEditorPause);
- }
- void Destruct(Notification note)
- {
- PoolObject poolObject = GetComponent<PoolObject>();
- if (poolObject != null)
- {
- poolObject.Despawn();
- } else
- {
- AVDebug.LogWarning("Should we use a Pool for this object? - " + name);
- Destroy(gameObject);
- }
- }
- }
|