summaryrefslogtreecommitdiff
path: root/GameCode/ChargeFeedback.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/ChargeFeedback.cs
+ init
Diffstat (limited to 'GameCode/ChargeFeedback.cs')
-rw-r--r--GameCode/ChargeFeedback.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/GameCode/ChargeFeedback.cs b/GameCode/ChargeFeedback.cs
new file mode 100644
index 0000000..322fe89
--- /dev/null
+++ b/GameCode/ChargeFeedback.cs
@@ -0,0 +1,44 @@
+using UnityEngine;
+
+public class ChargeFeedback : MonoBehaviour
+{
+ private Gun gun;
+
+ public float drag = 1f;
+
+ public float spring = 1f;
+
+ public float angle = 45f;
+
+ public float chargeAngle = 15f;
+
+ private float currentAngle;
+
+ private float velocity;
+
+ public float charge;
+
+ private void Start()
+ {
+ gun = GetComponentInParent<Gun>();
+ gun.AddAttackAction(Shoot);
+ }
+
+ private void Update()
+ {
+ charge = 0f;
+ if (!gun.IsReady(0.15f))
+ {
+ charge = 1f;
+ }
+ velocity += (charge * chargeAngle - currentAngle) * CappedDeltaTime.time * spring;
+ velocity -= velocity * CappedDeltaTime.time * drag;
+ currentAngle += CappedDeltaTime.time * velocity;
+ base.transform.localEulerAngles = new Vector3(currentAngle, 0f, 0f);
+ }
+
+ public void Shoot()
+ {
+ velocity += (0f - angle) * 1000f * (gun.damage / 55f);
+ }
+}