| 123456789101112131415161718192021222324252627282930313233343536373839 |
- // Shatter Toolkit
- // Copyright 2015 Gustav Olsson
- using UnityEngine;
- namespace ShatterToolkit.Helpers
- {
- [RequireComponent(typeof(ShatterTool))]
- public class PieceRemover : MonoBehaviour
- {
- public int startAtGeneration = 3;
- public float timeDelay = 1.0f;
-
- protected ShatterTool shatterTool;
- protected float timeSinceInstantiated;
- protected Vector3 originalScale;
-
- public void Start()
- {
- shatterTool = GetComponent<ShatterTool>();
- originalScale = gameObject.transform.localScale;
- }
-
- public void Update()
- {
- if (shatterTool.Generation >= startAtGeneration)
- {
- Vector3 currentScale = (timeDelay - timeSinceInstantiated / timeDelay) * originalScale;
- gameObject.transform.localScale = currentScale;
- timeSinceInstantiated += Time.deltaTime;
-
- if (timeSinceInstantiated >= timeDelay)
- {
- Destroy(gameObject);
- }
- }
- }
- }
- }
|