Mobile input system for yandex games

Hi, I have a problem with Input System for mobile in Yandex Games. It works in Editor when I turn on test mobile mode, and works in Web for PC, but doesn’t work on mobile at all.

Here’s my script. Thanks in advance!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using romanlee17.MirraGames;

public class UnifiedController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [Header("Movement")]
    [SerializeField] private float moveSpeed = 5f;
    [SerializeField] private float runSpeed = 5f;
    [SerializeField] private Rigidbody _rigidbody;

    [Header("Joystick (Mobile)")]
    [SerializeField] private VariableJoystick _joystick;

    [Header("Camera (Swipe)")]
    [SerializeField] private Transform cameraTransform;
    [SerializeField] private float swipeSensitivity = 0.2f;
    [SerializeField] private float maxAngleUp = 80f;
    [SerializeField] private float maxAngleDown = -80f;
    [SerializeField] private Vector3 cameraOffset = new Vector3(0, 1.6f, 0);

    [Header("Swipe Panel (UI)")]
    [SerializeField] private RectTransform swipePanel;

    [Header("Debug")]
    [SerializeField] private bool forceMobileMode = false;

    private bool isMobile;
    private MyPlayer pl;
    private ScreenNormal screenNormal;

    private float rotationX, rotationY;
    private Vector2 swipeStartPos;
    private bool isDragging = false;
    private int pointerId = -1;

    void Awake()
    {
        isMobile = forceMobileMode || MirraSDK.Device.IsMobile;

        if (!isMobile)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = false;
            MirraSDK.Device.CursorVisible = false;
            MirraSDK.Device.CursorLock = CursorLockMode.Locked;
        }
        else if (_joystick != null)
        {
            _joystick.gameObject.SetActive(true);
        }
    }

    void Start()
    {
        pl = GetComponent<MyPlayer>();
        screenNormal = FindObjectOfType<ScreenNormal>();
        rotationY = transform.eulerAngles.y;
    }

    void Update()
    {
        if (isMobile)
        {
            HandleSwipeInput();
        }
        else
        {
            HandleRotation();
            HandleInteraction();
        }
    }

    void FixedUpdate()
    {
        if (isMobile)
        {
            HandleMovementMobile();
            ApplySwipeRotation();
        }
        else
        {
            HandleMovementPC();
        }
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        if (RectTransformUtility.RectangleContainsScreenPoint(swipePanel, eventData.position))
        {
            isDragging = true;
            swipeStartPos = eventData.position;
            pointerId = eventData.pointerId;
        }
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (eventData.pointerId == pointerId)
        {
            isDragging = false;
            pointerId = -1;
        }
    }

    private void HandleSwipeInput()
    {
        if (!isDragging) return;

        Vector2 currentPos = Input.mousePosition;

        Vector2 delta = currentPos - swipeStartPos;
        swipeStartPos = currentPos;

        float deltaX = delta.x * swipeSensitivity;
        float deltaY = -delta.y * swipeSensitivity;

        rotationX = Mathf.Clamp(rotationX + deltaY, maxAngleDown, maxAngleUp);
        rotationY += deltaX;
    }

    private void ApplySwipeRotation()
    {
        cameraTransform.localRotation = Quaternion.Euler(rotationX, 0, 0);
        transform.rotation = Quaternion.Euler(0, rotationY, 0);
        cameraTransform.position = transform.position + cameraOffset;
    }

    private void HandleMovementMobile()
    {
        Vector3 moveDirection = new Vector3(_joystick.Horizontal, 0, _joystick.Vertical);
        Vector3 localMove = transform.TransformDirection(moveDirection) * moveSpeed;

        _rigidbody.linearVelocity = new Vector3(localMove.x, _rigidbody.linearVelocity.y, localMove.z);
        _rigidbody.AddForce(localMove * runSpeed * Time.fixedDeltaTime, ForceMode.VelocityChange);

        if (pl != null)
        {
            float mag = moveDirection.magnitude;
            if (mag > 0.8f)
                pl.animState = 1;
            else if (mag > 0.2f)
                pl.animState = 4;
            else
                pl.animState = 0;
        }
    }

    private void HandleMovementPC()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        Vector3 move = new Vector3(h, 0, v);
        Vector3 localMove = transform.TransformDirection(move) * moveSpeed;

        _rigidbody.linearVelocity = new Vector3(localMove.x, _rigidbody.linearVelocity.y, localMove.z);
        _rigidbody.AddForce(localMove * runSpeed * Time.fixedDeltaTime, ForceMode.VelocityChange);

        if (pl != null)
        {
            float mag = move.magnitude;
            if (mag > 0.8f)
                pl.animState = 1;
            else if (mag > 0.2f)
                pl.animState = 4;
            else
                pl.animState = 0;
        }
    }

    private void HandleRotation()
    {
        float inputX = Input.GetAxis("Mouse X");
        float inputY = Input.GetAxis("Mouse Y");

        rotationX -= inputY * swipeSensitivity * 10f;
        rotationX = Mathf.Clamp(rotationX, maxAngleDown, maxAngleUp);
        cameraTransform.localRotation = Quaternion.Euler(rotationX, 0, 0);

        rotationY += inputX * swipeSensitivity * 10f;
        transform.rotation = Quaternion.Euler(0, rotationY, 0);
        cameraTransform.position = transform.position + cameraOffset;
    }

    private void HandleInteraction()
    {
        if (screenNormal == null) return;

        if (Input.GetKeyDown(KeyCode.F)) screenNormal.OnReportPressed();
        if (Input.GetMouseButtonDown(0))
        {
            screenNormal.OnKillPressed();
            screenNormal.OnUsePressed();
        }

        if (Input.GetMouseButtonDown(1)) screenNormal.OnMapToggle();
        if (Input.GetKeyDown(KeyCode.Escape)) screenNormal.SetPause();
    }
}

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

If you find out more and it is still mysterious, try this template:

How to report your problem productively in the Unity3D forums:

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.