I need to optimize the code for android. make it so that when you press the ui buttons, the object moves, please help here is the code itself:
using System;
using System.Collections.Generic;
using UnityEngine;
public enum Axel
{
Front,
Rear
}
[Serializable]
public struct Wheel
{
public GameObject model;
public WheelCollider collider;
public Axel axel;
}
public class CarController : MonoBehaviour
{
[SerializeField]
private float maxAcceleration = 3.0f;
[SerializeField]
private float turnSensitivity = 10.0f;
[SerializeField]
private float maxSteerAngle = 45.0f;
[SerializeField]
private Vector3 _centerOfMass;
[SerializeField]
private List wheels;
private float inputX, inputY;
private Rigidbody _rb;
private void Start()
{
_rb = GetComponent();
_rb.centerOfMass = _centerOfMass;
}
private void Update()
{
AnimateWheels();
GetInputs();
}
private void LateUpdate()
{
Move();
Turn();
}
private void GetInputs()
{
inputX = Input.GetAxis(“Horizontal”);
inputY = Input.GetAxis(“Vertical”);
}
private void Move()
{
foreach (var wheel in wheels)
{
wheel.collider.motorTorque = inputY * maxAcceleration * 500 * Time.deltaTime;
}
}
private void Turn()
{
foreach (var wheel in wheels)
{
if (wheel.axel == Axel.Front)
{
var _steerAngle = inputX * turnSensitivity * maxSteerAngle;
wheel.collider.steerAngle = Mathf.Lerp(wheel.collider.steerAngle,_steerAngle,0.5f);
}
}
}
private void AnimateWheels()
{
foreach (var wheel in wheels)
{
Quaternion _rot;
Vector3 _pos;
wheel.collider.GetWorldPose(out _pos, out _rot);
wheel.model.transform.position = _pos;
wheel.model.transform.rotation = _rot;
}
}
}