Unity 3D Game Dev Day 6: Quick Mobile Migration of Our Game.

I just use my other project's joystick code and make it on the canvas. Change the input system.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ARObjectController : MonoBehaviour
{
    [SerializeField] private float moveSpeed;

    private FixedJoystick joystick;
    private Rigidbody rb;

    private void OnEnable()
    {
        joystick = FindObjectOfType<FixedJoystick>();
        rb = gameObject.GetComponent<Rigidbody>();
    }

    private void Update()
    {
       float xMovement = joystick.Horizontal;
       float zMovement = joystick.Vertical;

       Vector3 movement = new Vector3(xMovement, 0, zMovement);
       rb.velocity = movement * moveSpeed;

       if(xMovement != 0 && zMovement != 0)
       {
           transform.eulerAngles = new Vector3(transform.eulerAngles.x, Mathf.Atan2(xMovement, zMovement) * Mathf.Rad2Deg, transform.eulerAngles.z);
       }

    }
}

And then we can play our game on mobile.

image-20240123174350148