diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/RemoveAfterSeconds.cs |
+ init
Diffstat (limited to 'GameCode/RemoveAfterSeconds.cs')
-rw-r--r-- | GameCode/RemoveAfterSeconds.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/GameCode/RemoveAfterSeconds.cs b/GameCode/RemoveAfterSeconds.cs new file mode 100644 index 0000000..8232562 --- /dev/null +++ b/GameCode/RemoveAfterSeconds.cs @@ -0,0 +1,54 @@ +using UnityEngine; + +public class RemoveAfterSeconds : MonoBehaviour +{ + public float seconds = 3f; + + private float startSeconds; + + public bool shrink; + + public bool scaleWithScale; + + private float shrinkSpeed = 1f; + + private Vector3 startScale; + + private AnimationCurve curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); + + private float counter; + + private void Start() + { + startSeconds = seconds; + startScale = base.transform.localScale; + shrinkSpeed = Random.Range(1.5f, 2.5f); + } + + private void Update() + { + seconds -= TimeHandler.deltaTime * (scaleWithScale ? (1f / base.transform.localScale.x) : 1f); + if (!(seconds < 0f)) + { + return; + } + if (shrink) + { + counter += Time.deltaTime * shrinkSpeed; + base.transform.localScale = Vector3.Lerp(startScale, Vector3.zero, curve.Evaluate(counter)); + if (counter > 1f) + { + Object.Destroy(base.gameObject); + } + } + else + { + Object.Destroy(base.gameObject); + } + } + + public void ResetCounter() + { + seconds = startSeconds; + } +} |