From d4de0598ddc7a067a5ad2327af2eb8ede4527afb Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Fri, 18 Mar 2022 12:53:30 +0200 Subject: [PATCH] fix: bug when scores add even when tap outside a ball --- Assets/_Scripts/Managers/ScoreManager.cs | 8 ++++---- Assets/_Scripts/PlayerScripts/PlayerController.cs | 2 ++ Assets/_Scripts/PlayerScripts/PlayerEvents.cs | 4 ++-- Assets/_Scripts/PlayerScripts/PlayerInput.cs | 2 -- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/_Scripts/Managers/ScoreManager.cs b/Assets/_Scripts/Managers/ScoreManager.cs index dff8630..12ec088 100644 --- a/Assets/_Scripts/Managers/ScoreManager.cs +++ b/Assets/_Scripts/Managers/ScoreManager.cs @@ -21,8 +21,8 @@ public class ScoreManager : MonoBehaviour { // Get _bestAllTimeScore if available or set it to 0 - PlayerEvents.OnScreenTouched += AddScore; - PlayerEvents.OnScreenTouched += AddExperience; + PlayerEvents.OnBallTouched += AddScore; + PlayerEvents.OnBallTouched += AddExperience; PlayerEvents.OnWallTouched += ResetMultiplierAndReward; } @@ -64,8 +64,8 @@ public class ScoreManager : MonoBehaviour private void OnDestroy() { - PlayerEvents.OnScreenTouched -= AddScore; - PlayerEvents.OnScreenTouched -= AddExperience; + PlayerEvents.OnBallTouched -= AddScore; + PlayerEvents.OnBallTouched -= AddExperience; PlayerEvents.OnWallTouched -= ResetMultiplierAndReward; } } diff --git a/Assets/_Scripts/PlayerScripts/PlayerController.cs b/Assets/_Scripts/PlayerScripts/PlayerController.cs index 1f9dce0..9d12dd4 100644 --- a/Assets/_Scripts/PlayerScripts/PlayerController.cs +++ b/Assets/_Scripts/PlayerScripts/PlayerController.cs @@ -45,6 +45,8 @@ public class PlayerController : MonoBehaviour _rigidbody.AddForce(_punchForce * new Vector2(bounceDir.x * _sideForceMultiplier, _upForceMultiplier), ForceMode2D.Impulse); //Add angular velocity for the visual effect _rigidbody.angularVelocity += bounceDir.x * -360f; + + PlayerEvents.SendBallTouched(); } private void Update() diff --git a/Assets/_Scripts/PlayerScripts/PlayerEvents.cs b/Assets/_Scripts/PlayerScripts/PlayerEvents.cs index 7f5412a..f86311d 100644 --- a/Assets/_Scripts/PlayerScripts/PlayerEvents.cs +++ b/Assets/_Scripts/PlayerScripts/PlayerEvents.cs @@ -2,13 +2,13 @@ using System; public class PlayerEvents { - public static event Action OnScreenTouched; + public static event Action OnBallTouched; public static event Action OnWallTouched; public static event Action OnFloorTouched; - public static void SendScreenTouched() => OnScreenTouched?.Invoke(); + public static void SendBallTouched() => OnBallTouched?.Invoke(); public static void SendWallTouched() => OnWallTouched?.Invoke(); diff --git a/Assets/_Scripts/PlayerScripts/PlayerInput.cs b/Assets/_Scripts/PlayerScripts/PlayerInput.cs index 7b0b174..451289b 100644 --- a/Assets/_Scripts/PlayerScripts/PlayerInput.cs +++ b/Assets/_Scripts/PlayerScripts/PlayerInput.cs @@ -12,7 +12,6 @@ public class PlayerInput : MonoBehaviour if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame) { _playerController.OnTouch(_camera.ScreenToWorldPoint(Mouse.current.position.ReadValue())); - PlayerEvents.SendScreenTouched(); return; } @@ -20,7 +19,6 @@ public class PlayerInput : MonoBehaviour if (Touchscreen.current != null && Touchscreen.current.primaryTouch.press.wasPressedThisFrame) { _playerController.OnTouch(_camera.ScreenToWorldPoint(Touchscreen.current.touches[0].position.ReadValue())); - PlayerEvents.SendScreenTouched(); return; } }