Guest User

Untitled

a guest
Oct 1st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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. /// <summary>
  10. /// Follows the target transform forever, and despawns if/when the target goes away
  11. /// </summary>
  12. public class FollowingAutoDespawner : AutoDespawner
  13. {
  14. protected Transform followTransform = null;
  15. protected bool isFollowing = false;
  16.  
  17. public void SetFollowing(Transform followThis)
  18. {
  19. followTransform = followThis;
  20. isFollowing = (followTransform != null) ? true : false;
  21. }
  22.  
  23. protected override void OnSpawned(SpawnPool ourSpawnPool)
  24. {
  25. followTransform = null;
  26. isFollowing = false;
  27.  
  28. base.OnSpawned(ourSpawnPool);
  29. }
  30.  
  31. protected override void Update()
  32. {
  33. if (followTransform != null)
  34. {
  35. this.gameObject.transform.position = followTransform.position;
  36. this.gameObject.transform.rotation = followTransform.rotation;
  37. }
  38.  
  39. base.Update();
  40. }
  41.  
  42. protected override bool ShouldDespawn(float deltaTime)
  43. {
  44. // If we're following something, and that something goes inactive or self-destructs, despawn us
  45. if ((followTransform != null) && (!followTransform.gameObject.activeInHierarchy)) { return true; }
  46. else if ((followTransform == null) && isFollowing) { return true; }
  47.  
  48. return base.ShouldDespawn(deltaTime);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment