Reputation: 683
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
Upvotes: 0
Views: 1874
Reputation: 125445
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.
Upvotes: 2