Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- using PathologicalGames;
- namespace SpartanFist
- {
- public class AutoDespawner : MonoBehaviour
- {
- protected SpawnPool owningPool;
- protected virtual void OnSpawned(SpawnPool ourSpawnPool)
- {
- owningPool = ourSpawnPool;
- }
- protected virtual void OnDespawned(SpawnPool ourSpawnPool)
- {
- // (we cease caring about what owns us once we're despawned)
- owningPool = null;
- }
- protected virtual void Update()
- {
- float deltaTime = PhysicsManager.GetDeltaTimeFor(gameObject);
- if (ShouldDespawn(deltaTime))
- {
- if (owningPool != null)
- {
- SpawnPools.Despawn(transform, owningPool);
- }
- else
- {
- Debug.LogWarning("Orphaned object '" + gameObject.name + "' had no spawnpool, and was thus unable to despawn properly. Object deactived.");
- gameObject.SetActive(false);
- }
- }
- }
- protected virtual bool ShouldDespawn(float deltaTime)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment