Made GlobalInput work with mobile

This commit is contained in:
Pasha Bibko
2025-11-27 10:48:09 +00:00
parent d61a44b1dc
commit 8291d627c1
2 changed files with 47 additions and 3 deletions

View File

@@ -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<InputTracker>();
}
private static InputTracker s_InputTracker;
public static bool IsScreenClicked => s_InputTracker._IsScreenClicked();
public static bool IsScreenHeld => s_InputTracker._IsScreenHeld();
}

View File

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