From e76f819a0f64a3b0c09d5e93c77d53622d59715c Mon Sep 17 00:00:00 2001 From: Unknown <34045228+sommerlilie@users.noreply.github.com> Date: Sun, 22 Apr 2018 22:07:57 +0200 Subject: [PATCH] Update BrakeBarController --- Assets/Scripts/BrakeBarController.cs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/BrakeBarController.cs b/Assets/Scripts/BrakeBarController.cs index 0a243ff..18692f6 100644 --- a/Assets/Scripts/BrakeBarController.cs +++ b/Assets/Scripts/BrakeBarController.cs @@ -7,7 +7,8 @@ public class BrakeBarController : MonoBehaviour { float currentRotation; int BrakeAmount = 100; private Player player; - int currentBrakeAmount; + float firstTime; + float secondTime; // Use this for initialization void Start () { @@ -19,22 +20,31 @@ public class BrakeBarController : MonoBehaviour { // if player alive and spawned if (player != null) { - UpdatePointer(currentBrakeAmount); + UpdatePointer(); } else if (currentRotation != 0) { //if player dead or not spawned - UpdatePointer(0); + UpdatePointer(); } } - private void UpdatePointer(float brakeAmount) + private void UpdatePointer() { - if (Input.GetKey(KeyCode.S)) { - float offset = brakeAmount - currentRotation; - gameObject.transform.Rotate(Vector3.forward, offset); - currentRotation += offset; + if (Input.GetKeyDown(KeyCode.S)) + { + firstTime = Time.time; + } + + if (Input.GetKeyUp(KeyCode.S)) + { + secondTime = Time.time; + float difference = secondTime - firstTime; + gameObject.transform.Rotate(Vector3.forward, difference); + } + + } } -} +