How to use Input.Getaxis("Horizontal") With touch screen to jump/move

Hello all,

Currently I’m trying to get a little 2d game going however I want to stay away from an on screen touch pad / button if possible.

What I would like to achieve is the same kind of control as in the standard 2d side scroller however I want to do this with the touch commands.

Now I kind of figured out how to move left and right with Input.GetTouch, and Input.TouchCount however what is tripping me up is the jumping. I would like it so when the player presses&holds on the screen the character in the game runs in that direction. Since its a 2D game this will either be left or right(X axis) However when the player taps the screen I would like the character to jump.

I can’t seem to get this to work and I’m not sure where to start as the I don’t know how the game would differentiate between when the player is taping/holding on the screen to run in a direction and when it will be a jump as it would see the original tap to move the character.

I thought about just having the player hold down on the screen and scroll in the up direction(Till it hits the Y Axis) to get the character to jump but I don’t know if that would really work either.

If this is a limitation of touch abilities just let me know and I’ll start looking into a on screen game pad system. If someone can however think of a way to get this to work or point me in the right direction that would be great.

Many thanks,

You could cover the entire screen with an invisible Collider2D set as Trigger. Then you can take adavantage of mouse events (user touch events), such as onMouseUpAsButton (for Jumping), and onMouseDrag (for moving left/right). Note you will need to take the extra step of having onMouseUpAsButton compare the mouse down coordinate against the mouse up coordinate to ensure the user didn’t a lazy tap such as touching, slightly dragging, then letting go.