summaryrefslogtreecommitdiff
path: root/GameCode/ScaleShake.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/ScaleShake.cs
+ init
Diffstat (limited to 'GameCode/ScaleShake.cs')
-rw-r--r--GameCode/ScaleShake.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/GameCode/ScaleShake.cs b/GameCode/ScaleShake.cs
new file mode 100644
index 0000000..b2a25b2
--- /dev/null
+++ b/GameCode/ScaleShake.cs
@@ -0,0 +1,76 @@
+using System.Collections;
+using Photon.Pun;
+using UnityEngine;
+
+public class ScaleShake : MonoBehaviour
+{
+ public bool useTimeScale = true;
+
+ public float targetScale = 1f;
+
+ public float multiplier = 1f;
+
+ private float velocity;
+
+ public float drag = 1f;
+
+ public float spring = 1f;
+
+ public float clampVelocity;
+
+ internal float high;
+
+ internal float low;
+
+ private void Update()
+ {
+ float num = Mathf.Clamp(useTimeScale ? TimeHandler.deltaTime : Time.unscaledDeltaTime, 0f, 0.02f);
+ if (clampVelocity != 0f)
+ {
+ velocity = Mathf.Clamp(velocity, 0f - clampVelocity, clampVelocity);
+ }
+ velocity += (targetScale - base.transform.localScale.x) * num * 50f * spring;
+ velocity -= drag * velocity * 20f * num;
+ base.transform.localScale += Vector3.one * (velocity * 10f * num);
+ }
+
+ public void AddForce(float force)
+ {
+ velocity += force * multiplier * 5f;
+ }
+
+ public void AddForce()
+ {
+ velocity += 1f * multiplier * 5f;
+ }
+
+ public void SetTarget(float target)
+ {
+ targetScale = target;
+ }
+
+ public void SetHigh()
+ {
+ targetScale = high;
+ }
+
+ public void SetLow()
+ {
+ targetScale = low;
+ }
+
+ public void ScaleOutRootPhoton()
+ {
+ StartCoroutine(GoAwayOutRootPhoton());
+ }
+
+ private IEnumerator GoAwayOutRootPhoton()
+ {
+ while (base.transform.localScale.x > 0f)
+ {
+ targetScale = 0f;
+ yield return null;
+ }
+ PhotonNetwork.Destroy(base.transform.root.gameObject);
+ }
+}