Hi I really need help have put over 30 hours into a pc game, I've been working off of many tutourial

this is my current player movement script

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

// This is a reference to the Rigidbody component called “rb”
public Rigidbody rb;

public float forwardForce = 2000f; // Variable that determines the forward force
public float sidewaysForce = 500f; // Variable that determines the sideways force

// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate ()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);

if (Input.GetKey(“d”)) // If the player is pressing the “d” key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

if (Input.GetKey(“a”)) // If the player is pressing the “a” key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

if (rb.position.y < -1f)
{
FindObjectOfType().EndGame();
}
}
}

I would like to change this to a mobile game, so I need to somehow learn hoe to make the get key d command and a into button commands. Each button would take up half the screen and when held like a key would add a sideways force to the player. Thanks in advance.

Please always use code tags when you post code on the forums. You can learn how to this here: https://discussions.unity.com/t/481379

You can learn how to use touch controls in Unity here: https://docs.unity3d.com/Manual/MobileInput.html
And you can watch this beginner’s tutorial here:

https://www.youtube.com/watch?v=bp2PiFC9sSs

After that when you have concrete questions, we’re here to help.

1 Like

You say 30 hours like that’s a lot or something :stuck_out_tongue:

You could implement buttons you press on the screen, or what I’d probably do is a virtual joystick. There’s a few good assets on the Asset Store for virtual or touch joysticks.

i dont know if its a good solution but you could use Eventtrigger with pointer enter and exit to set a bool. Did this some years ago in a study project.