DespawnWhenOutOfScreen.cs 439 B

1234567891011121314151617181920212223
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// This component is used by the loading background sperms. They despawn when they go out of screen.
  5. /// </summary>
  6. public class DespawnWhenOutOfScreen : MonoBehaviour
  7. {
  8. PoolObject _poolObject;
  9. void Awake()
  10. {
  11. _poolObject = GetComponent<PoolObject>();
  12. }
  13. void Update()
  14. {
  15. if (transform.localPosition.x > GameConstants.GAME_WIDTH)
  16. {
  17. _poolObject.Despawn();
  18. }
  19. }
  20. }