Hello! I’m making a racing game and I wanted to port it over to mobile, but I’m having a lot of trouble trying to figure out the best way to do it. Initially, I thought that simulating a keypress with a UI button would work well but thanks to the help of @Hellium I’m now trying to figure out another way to port this game over. Here is the current code for the BaseInput:
using UnityEngine;
namespace KartGame.KartSystems
{
public struct InputData
{
public bool Accelerate;
public bool Brake;
public float TurnInput;
}
public interface IInput
{
InputData GenerateInput();
}
public abstract class BaseInput : MonoBehaviour, IInput
{
/// <summary>
/// Override this function to generate an XY input that can be used to steer and control the car.
/// </summary>
public abstract InputData GenerateInput();
}
}
And here is the keyboard input script, these “horizontal”, “accelerate” and “brake” buttons are all referencing to Unity’s input manager, as you can see in the image attached!
using UnityEngine;
namespace KartGame.KartSystems {
public class KeyboardInput : BaseInput
{
public string TurnInputName = "Horizontal";
public string AccelerateButtonName = "Accelerate";
public string BrakeButtonName = "Brake";
public override InputData GenerateInput() {
return new InputData
{
Accelerate = Input.GetButton(AccelerateButtonName),
Brake = Input.GetButton(BrakeButtonName),
TurnInput = Input.GetAxis("Horizontal")
};
}
}
}
What would be the best way to change this keyboard input method to a mobile-compatible one? Ideally, I would like a joystick for movement but left and right buttons would also be fine. Thanks again @Hellium for the help with the previous incorrect question that I’ve made!