Infinite Runner 2D sample - Jump does't work on mobile

Hello,

I’m new to Unity and started with the 2D tutorial of Infinite Runner, which is also on the Asset store.
Link:

It works flawlessly on PC, and it installs successfully to mobile (Android, Windows Phone) but the jump key doesn’t work on mobile - I guess it is somehow hardcoded to the “Space” key in a PC keyboard and needs to be adjusted to tap gestures on mobile.

How can I fix this?

Thanks,
Noam

Can anyone help on this?

Thanks,
Noam

Have you looked in the documentation for handling touch events?

That won’t give you the exact code to just “plug in” to the 2D runner tutorial, but hopefully you can figure it out.

You’ll probably also want to write the code so that it looks to see what device it is on (or was built for) and uses the correct input code. That way you don’t end up with two different codebases.

Jay

Hi - I’ve read the doc and was able to find the peace of code to put in order to make it recognize taps.

But - in other threads I’ve seen people going to the Project Settings → Input and manipulating the configuration there. I looked at this menu and saw that “space” is attached to “jump” but I didn’t understand if I can configure touch events via this menu.

So, as a developer, I’m not sure where is the right place, or best practice, to add this code.

If you could be more specific to where would you put such code, let me know.

Thanks,
Noam

There are two ways to implement something:

  1. The best way.
  2. Any way that works.

It’s always nice when what you do turns out to be option #1, but I’m a firm believer in doing #2 if that’s all you can figure out. Get it working first, optimize (if necessary) second.

I’m saying that because I don’t actually know the best practice for this specific problem. :slight_smile:

I think the Project settings are only good for keyboard, mouse, and joystick tweaking, not for touch. Those things have to be done via code, I believe.

Unless someone with a lot of experience comes along, I say go with whatever works. At least for now. Sorry I don’t have a chunk of code to give you that would solve the problem.

Jay

PS - I’m not new to game dev, but I’m new to Unity.