diff options
| author | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-11-02 11:51:31 +0800 |
| commit | 7f493f682503f5186308de7b8f74b5b49233cfe4 (patch) | |
| tree | 8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/ScaleAnimation.cs | |
+init
Diffstat (limited to 'GameCode/ScaleAnimation.cs')
| -rw-r--r-- | GameCode/ScaleAnimation.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/GameCode/ScaleAnimation.cs b/GameCode/ScaleAnimation.cs new file mode 100644 index 0000000..4cd8dd7 --- /dev/null +++ b/GameCode/ScaleAnimation.cs @@ -0,0 +1,42 @@ +using System.Collections; +using UnityEngine; + +public class ScaleAnimation : OneShotAnimationBase +{ + public AnimationCurve curve; + + public float duration = 0.75f; + + public float targetScale; + + public Transform transformToAnimate; + + private float initialScale = 1f; + + private void Start() + { + initialScale = transformToAnimate.localScale.x; + } + + private IEnumerator Animate() + { + transformToAnimate.localScale = Vector3.one * initialScale; + float timer = 0f; + while (timer < duration) + { + transformToAnimate.localScale = Vector3.one * Mathf.Lerp(initialScale, targetScale, curve.Evaluate(timer / duration)); + timer += Time.deltaTime; + yield return null; + } + transformToAnimate.localScale = Vector3.one * Mathf.Lerp(initialScale, targetScale, curve.Evaluate(timer / duration)); + } + + public override void Trigger() + { + if (base.gameObject.activeInHierarchy) + { + StopAllCoroutines(); + StartCoroutine(Animate()); + } + } +} |
