fix: bug when scores add even when tap outside a ball

This commit is contained in:
cuqmbr 2022-03-18 12:53:30 +02:00
parent 5bceed3436
commit d4de0598dd
4 changed files with 8 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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()

View File

@ -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();

View File

@ -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;
}
}