Я также создаю свою игру для работы в SteamDeck.
Я пытаюсь использовать джойстик для управления курсором /мышью.
и щелкну на кнопку x.
По какой -то причине, когда я использую джойстик, я не могу видеть значок курсора. Значок курсора.
(на ПК он работает - используя мышь)
, и если я использую сенсорную панель, значок курсора, кажется, появляется на мгновение.public class InputManager : MonoBehaviour
{
public static InputManager Instance { get; private set; }
private PlayerControls playerControls;
private float lastClickTime = 0f;
public Vector2 CursorScreenPosition { get; private set; }
private void OnEnable() => playerControls.Enable();
private void OnDisable() => playerControls.Disable();
private void Awake()
{
if(Instance != null&& Instance != this){Destroy(gameObject); return; }
Instance = this;
playerControls = new PlayerControls();
playerControls.Gameplay.Click.performed += ctx => OnClick();
playerControls.Gameplay.CursorPosition.performed += ctx =>
{
Vector2 input = ctx.ReadValue();
if (input.sqrMagnitude > 0.0001f)
{
if (CursorScreenPosition == Vector2.zero)
CursorScreenPosition = new Vector2(Screen.width / 2f, Screen.height / 2f);
float cursorSpeed = 800f;
CursorScreenPosition += input * cursorSpeed * Time.deltaTime;
CursorScreenPosition = new Vector2(
Mathf.Clamp(CursorScreenPosition.x, 0, Screen.width),
Mathf.Clamp(CursorScreenPosition.y, 0, Screen.height)
);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
Mouse.current.WarpCursorPosition(CursorScreenPosition);
}
};
}
private void OnClick()
{
float clickDelay = 0.5f;
if (Time.time - lastClickTime >= clickDelay)
{
lastClickTime = Time.time;
Debug.Log("Click detected!");
}
}
public bool IsClickPerformed()
{
return playerControls.Gameplay.Click.WasPerformedThisFrame();
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... k-joystick