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
- {
- /// <summary>
- /// Follows the target transform forever, and despawns if/when the target goes away
- /// </summary>
- public class FollowingAutoDespawner : AutoDespawner
- {
- protected Transform followTransform = null;
- protected bool isFollowing = false;
- public void SetFollowing(Transform followThis)
- {
- followTransform = followThis;
- isFollowing = (followTransform != null) ? true : false;
- }
- protected override void OnSpawned(SpawnPool ourSpawnPool)
- {
- followTransform = null;
- isFollowing = false;
- base.OnSpawned(ourSpawnPool);
- }
- protected override void Update()
- {
- if (followTransform != null)
- {
- this.gameObject.transform.position = followTransform.position;
- this.gameObject.transform.rotation = followTransform.rotation;
- }
- base.Update();
- }
- protected override bool ShouldDespawn(float deltaTime)
- {
- // If we're following something, and that something goes inactive or self-destructs, despawn us
- if ((followTransform != null) && (!followTransform.gameObject.activeInHierarchy)) { return true; }
- else if ((followTransform == null) && isFollowing) { return true; }
- return base.ShouldDespawn(deltaTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment