Hi guys, I’m making a 2d platformer and I can make the player move horizontally, but becuase I’m making it for android I’ve stumbled across a huge problem. I can’t control the player when on android. I thought about trying to use buttons on the GUI and also by using a script I found online to split the screen into two halves and then each side does a certain thing. I got nowhere with the buttons, but the other one I thought might be better anyway. All I need is a script that will let you move in one direction, then I can use this to finish the script.
Here is what I have so far…
public class Movement : MonoBehaviour {
private Rigidbody2D rb2d;
public float speed = 10f;
void Start () {
rb2d = GetComponent ();
}
void Update () {
float moveHorizontal = Input.GetAxis (“Horizontal”);
Vector2 movement = new Vector2 (moveHorizontal, 0.0f);
rb2d.AddForce (movement * speed);
}
}
And then if I add in
if(Input.touchCount ==1)
{
Touch touch =Input.touches[0];
if(touch.position.x Screen.width/2)
//Something that does what you need if rightside is touched
}
This should make it so that the screen is separated into the two halves and each side activates movement in the corresponding direction. I basically need those two parts of the script filling to move left and right.
Halp plz :,(