I have a 3rd-person controller in my Unity scene, which I can only control with the WASD buttons. But since I plan to make a smartphone game, I wonder how I can change these controls t swipe up/down/right/left and (if possible) keep WASD for debugging.


Do this in character controller script's Update()

First of all you have to detect the user input via touch(begin/moved/ended) methods and then you have to calculate the gesture it ended up in like swipe-left. You can assign a bool to it like SwipeL = true;

Now you have to add a condition in the methods where character movement is mapped with Input.GetKey("A") etc and append your bool with OR condition


if(Input.GetKey("A") || SwipeL)
//code for moving left

You need to do this for all key mappings.

  • \$\begingroup\$ Great! Thank you. Unfortunately though, the 3rd Person Controller-Script is written in Javascript \$\endgroup\$ – IMX Dec 14 '13 at 16:26
  • 3
    \$\begingroup\$ @IMX Your question is not tagged with a specific language. And this answer is just showing an example. The technique described can be implemented in any language Unity supports. \$\endgroup\$ – MichaelHouse Dec 14 '13 at 17:28
  • \$\begingroup\$ if statements in javascript and c# are analogous for the purpose of this example \$\endgroup\$ – Gerard Simpson Aug 2 '17 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.