// 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(); 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); } } } } }