summaryrefslogtreecommitdiff
path: root/CodeAnimation.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CodeAnimation.cs')
-rw-r--r--CodeAnimation.cs63
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();
+ }
+ }
+}