diff --git a/Assets/Scripts/GlobalInput.cs b/Assets/Scripts/GlobalInput.cs index fd0270d..d4532b5 100644 --- a/Assets/Scripts/GlobalInput.cs +++ b/Assets/Scripts/GlobalInput.cs @@ -2,8 +2,52 @@ using UnityEngine; public static class GlobalInput { - public static bool IsScreenClicked() + private class InputTracker : MonoBehaviour { - return Input.GetMouseButtonDown(0) || Input.touchCount > 0; + private void Start() => DontDestroyOnLoad(gameObject); + + [SerializeField] private bool m_IsContact; + [SerializeField] private bool m_TouchStartedThisFrame; + + private float m_HeldTime; + + private static bool IsPressedInternal() + { + return + Input.GetMouseButton(0) || + Input.anyKey || + Input.touchCount != 0; + } + + private void Update() + { + float tmp = m_HeldTime; + m_HeldTime = 0f; + + if (!IsPressedInternal()) + { + m_IsContact = false; + return; + } + + m_TouchStartedThisFrame = !m_IsContact; + m_IsContact = true; + + m_HeldTime = tmp + Time.unscaledDeltaTime; + } + + public bool _IsScreenClicked() => m_TouchStartedThisFrame; + public bool _IsScreenHeld() => m_IsContact && m_HeldTime > 0.5f; } + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Initialize() + { + GameObject go = new ("InputTracker"); + s_InputTracker = go.AddComponent(); + } + + private static InputTracker s_InputTracker; + + public static bool IsScreenClicked => s_InputTracker._IsScreenClicked(); + public static bool IsScreenHeld => s_InputTracker._IsScreenHeld(); } diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 24a8d55..c64408f 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -34,7 +34,7 @@ public class PlayerController : OrbitalPositionBehaviour if (s_PlayerScore > s_HighScore) m_ScoreText.color = Color.yellow; - if (GlobalInput.IsScreenClicked() && GlobalOrbitalPositionManager.AllowPlayerInput) + if (GlobalInput.IsScreenClicked && GlobalOrbitalPositionManager.AllowPlayerInput) { m_OrbitalPosition.m_AttachedRing += 1; }