1
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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

e.g.

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

You need to do this for all key mappings.

\$\endgroup\$
3
  • \$\begingroup\$ Great! Thank you. Unfortunately though, the 3rd Person Controller-Script is written in Javascript \$\endgroup\$
    – IMX
    Dec 14, 2013 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\$
    – House
    Dec 14, 2013 at 17:28
  • \$\begingroup\$ if statements in javascript and c# are analogous for the purpose of this example \$\endgroup\$ Aug 2, 2017 at 5:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .