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(); if (poolObject != null) { poolObject.Despawn(); } else { AVDebug.LogWarning("Should we use a Pool for this object? - " + name); Destroy(gameObject); } } }