From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/ChargeFeedback.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 GameCode/ChargeFeedback.cs (limited to 'GameCode/ChargeFeedback.cs') 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.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); + } +} -- cgit v1.1-26-g67d0