From 7f493f682503f5186308de7b8f74b5b49233cfe4 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 2 Nov 2023 11:51:31 +0800 Subject: +init --- GameCode/AnimateSizeAndDestroy.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 GameCode/AnimateSizeAndDestroy.cs (limited to 'GameCode/AnimateSizeAndDestroy.cs') diff --git a/GameCode/AnimateSizeAndDestroy.cs b/GameCode/AnimateSizeAndDestroy.cs new file mode 100644 index 0000000..7ec5b1a --- /dev/null +++ b/GameCode/AnimateSizeAndDestroy.cs @@ -0,0 +1,30 @@ +using System.Collections; +using UnityEngine; + +public class AnimateSizeAndDestroy : MonoBehaviour +{ + public AnimationCurve animationCurve; + + public float duration = 1f; + + private Vector3 initialScale; + + private void Start() + { + initialScale = base.transform.localScale; + StartCoroutine(AnimateScale()); + } + + private IEnumerator AnimateScale() + { + float time = 0f; + while (time <= duration) + { + float num = animationCurve.Evaluate(time / duration); + base.transform.localScale = initialScale * num; + time += Time.deltaTime; + yield return null; + } + Object.Destroy(base.gameObject); + } +} -- cgit v1.1-26-g67d0