0

So I'm trying to find a good tutorial which will explain how to controll character in 2D game when button is clicked (left, right, jump button).

All the tutorials I've found are outdated and not working.

Here's what I've tryed:

Created Button on Canvas and added C# script to it. Now I know how to control character with keyboard, but scince I' not developing for PC, that's useless for me.

I'm using something like this on PC:

GetComponent<Rigidbody2D>().velocity = new Vector3 (move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);

How can I convert it so it works for Android? For example, script that would move character to the right.

Thanks

DaxHR
  • 683
  • 1
  • 11
  • 30

1 Answers1

2

For controlling a character left right and forward and backward what you need is not just a button. You need a Virtual JoyStick. You use button for things like jump. Watch this video, it is no outdated.

For more examples about moving the character, look at the code in this question. The question contains code for moving the character with the keyboard and the answer explains how to move it with touch (Virtual JoyStick) on Android.

Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Thank you! JoyStick works like a charm although it needs a little bit of tweaking because reactions are to slow for platformer games. Do you maybe have some more usable, non-outdated Unity 2D Android tutorials? – DaxHR Apr 29 '16 at 22:39