PieceRemover.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Shatter Toolkit
  2. // Copyright 2015 Gustav Olsson
  3. using UnityEngine;
  4. namespace ShatterToolkit.Helpers
  5. {
  6. [RequireComponent(typeof(ShatterTool))]
  7. public class PieceRemover : MonoBehaviour
  8. {
  9. public int startAtGeneration = 3;
  10. public float timeDelay = 1.0f;
  11. protected ShatterTool shatterTool;
  12. protected float timeSinceInstantiated;
  13. protected Vector3 originalScale;
  14. public void Start()
  15. {
  16. shatterTool = GetComponent<ShatterTool>();
  17. originalScale = gameObject.transform.localScale;
  18. }
  19. public void Update()
  20. {
  21. if (shatterTool.Generation >= startAtGeneration)
  22. {
  23. Vector3 currentScale = (timeDelay - timeSinceInstantiated / timeDelay) * originalScale;
  24. gameObject.transform.localScale = currentScale;
  25. timeSinceInstantiated += Time.deltaTime;
  26. if (timeSinceInstantiated >= timeDelay)
  27. {
  28. Destroy(gameObject);
  29. }
  30. }
  31. }
  32. }
  33. }