Guest User

Untitled

a guest
Oct 1st, 2019
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.SceneManagement;
  5. using PathologicalGames;
  6.  
  7. namespace SpartanFist
  8. {
  9. public class AutoDespawner : MonoBehaviour
  10. {
  11. protected SpawnPool owningPool;
  12.  
  13. protected virtual void OnSpawned(SpawnPool ourSpawnPool)
  14. {
  15. owningPool = ourSpawnPool;
  16. }
  17.  
  18. protected virtual void OnDespawned(SpawnPool ourSpawnPool)
  19. {
  20. // (we cease caring about what owns us once we're despawned)
  21. owningPool = null;
  22. }
  23.  
  24. protected virtual void Update()
  25. {
  26. float deltaTime = PhysicsManager.GetDeltaTimeFor(gameObject);
  27. if (ShouldDespawn(deltaTime))
  28. {
  29. if (owningPool != null)
  30. {
  31. SpawnPools.Despawn(transform, owningPool);
  32. }
  33. else
  34. {
  35. Debug.LogWarning("Orphaned object '" + gameObject.name + "' had no spawnpool, and was thus unable to despawn properly. Object deactived.");
  36. gameObject.SetActive(false);
  37. }
  38. }
  39. }
  40.  
  41. protected virtual bool ShouldDespawn(float deltaTime)
  42. {
  43. return false;
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment