Last active
November 2, 2025 02:32
-
-
Save pr00thmatic/5f0134211a7dd7def2ef964c466a3678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace BitterSweetSuccess | |
| { | |
| public class NotTheHoldWeNeed_ButTheOneWeDeserve : MonoBehaviour | |
| { | |
| [Header("Initialization")] | |
| [SerializeField] private InputActionReference holdAction; | |
| [Header("Configuration")] | |
| [SerializeField] private float distanceToleranceInPixels = 20; | |
| void OnEnable () => naiveHoldAction.action.performed += HandleHoldPerformed; | |
| void OnDisable () => naiveHoldAction.action.performed -= HandleHoldPerformed; | |
| private void HandleHoldPerformed (InputAction.CallbackContext context) | |
| { | |
| if (context.control.parent is not TouchControl touch) | |
| return; // maybe it's a click or something else, idk... | |
| float powToleratedDistance = Mathf.Pow(distanceToleranceInPixels, 2); // pow is cheaper than sqrt | |
| if ((touch.startPosition.ReadValue() - touch.position.ReadValue()).sqrMagnitude <= powToleratedDistance) | |
| { | |
| OnHoldSuccess?.Invoke(touch.position.ReadValue()); | |
| } | |
| } | |
| public UnityEvent<Vector2> OnHoldSuccess { get; private set; } = new(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment