From b058493463d019ec466434ab8fa1bb1071b28d6e Mon Sep 17 00:00:00 2001
From: Ny Bruker <robinhs@stud.ntnu.no>
Date: Fri, 9 Dec 2022 17:52:36 +0100
Subject: [PATCH] Small fix to charging mechanic. - Can only start charging if
 ability is ready. - Can only release if it is actually charging.

---
 MrBigsock/Assets/Code/PlayerController.cs | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs
index 8678df36..35a1d4d7 100644
--- a/MrBigsock/Assets/Code/PlayerController.cs
+++ b/MrBigsock/Assets/Code/PlayerController.cs
@@ -212,19 +212,22 @@ namespace BigSock {
 				// Charge: Fire when let go.
 				case FireType.Charge:
 					// If pressed down: Store start time.
-					if (Input.GetKeyDown(key)) {
-						ability.ChargeStarted = Time.time;
+					if(Input.GetKeyDown(key)) {
+						// Only start charging if the ability is ready.
+						if(ability.Ability.Ready) ability.ChargeStarted = Time.time;
 						return true;
 					}
 					// If let go: Activate
-					else if (Input.GetKeyUp(key)) {
-						par.ChargeTime = ability.ChargeTime;
-						var t = ability.Ability.Use(par);
-						if (!t) {
-							if (par.ChargeTime < ability.Ability.MinCharge)
-								Debug.Log($"[PlayerController.CheckAbilityInput({key})] {ability.Ability.Name} not fired ({par.ChargeTime:N3} < {ability.Ability.MinCharge:N3})");
+					else if(Input.GetKeyUp(key)) {
+						if(ability.IsCharging) {
+							par.ChargeTime = ability.ChargeTime;
+							var t = ability.Ability.Use(par);
+							if (!t) {
+								if (par.ChargeTime < ability.Ability.MinCharge)
+									Debug.Log($"[PlayerController.CheckAbilityInput({key})] {ability.Ability.Name} not fired ({par.ChargeTime:N3} < {ability.Ability.MinCharge:N3})");
+							}
+							ability.ChargeStarted = 0f; // Reset charge time when we release the key.
 						}
-						ability.ChargeStarted = 0f; // Reset charge time when we release the key.
 						return true;
 					}
 					break;
-- 
GitLab