diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /CodeAnimation.cs |
+init
Diffstat (limited to 'CodeAnimation.cs')
-rw-r--r-- | CodeAnimation.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/CodeAnimation.cs b/CodeAnimation.cs new file mode 100644 index 0000000..a4d6244 --- /dev/null +++ b/CodeAnimation.cs @@ -0,0 +1,63 @@ +using System.Collections; +using UnityEngine; + +public class CodeAnimation : MonoBehaviour +{ + public bool x = true; + + public bool y = true; + + public bool z = true; + + public AnimationCurve curve; + + public bool loop; + + public bool playOnAwake; + + private void Start() + { + if (playOnAwake) + { + Play(); + } + } + + private void Update() + { + } + + public void Play() + { + StartCoroutine(PlayAnimation()); + } + + private IEnumerator PlayAnimation() + { + float t = 0f; + float lastFrameValue = curve.Evaluate(0f); + while (t < curve.keys[curve.length - 1].time) + { + t += Time.deltaTime; + float deltaValue = curve.Evaluate(t) - lastFrameValue; + lastFrameValue = curve.Evaluate(t); + if (x) + { + base.transform.localScale = new Vector3(base.transform.localScale.x + deltaValue, base.transform.localScale.y, base.transform.localScale.z); + } + if (y) + { + base.transform.localScale = new Vector3(base.transform.localScale.x, base.transform.localScale.y + deltaValue, base.transform.localScale.z); + } + if (z) + { + base.transform.localScale = new Vector3(base.transform.localScale.x, base.transform.localScale.y, base.transform.localScale.z + deltaValue); + } + yield return null; + } + if (loop) + { + Play(); + } + } +} |