- Home /
How to move and fire at same time with touchscreens? ( multitouch)
Hello Guys,
Could you explain how works goes with the multitouches? I want to move player object with one finger by touch joystick and with the others make fire by tapping ground. But when i move the player and fire with other finger at the same time, it does not perceive the tapping ground activity and this second touch affects on the joystick knob position. I think, i must distinguish the touch on the joystick object, from the other touches at the screen and look only that touch for moving action. How can i do that?
Answer by MD_Reptile · Sep 08, 2016 at 02:34 AM
Firstly, this has been answered many times in many places, including several other answers on this site, but anyway for the sake of learning here we go!
One thing you must do is enable multi touch input. In your input script (where your listening for button presses or touchscreen taps and whatnot) you will put into Start() or Awake() this code:
Input.multiTouchEnabled = true;
And then when your checking for input you need to check for more than just a single touch. Something like this:
int tapCount = Input.touchCount;
for ( int i = 0 ; i < tapCount ; i++ ) {
Touch touch = Input.GetTouch(i);
//Do whatever you want with the current touch.
}
And so from this point it all depends on what your game is setup like, maybe you need to check the position of that touch and see if it is over the joystick. Then if it is, and no other touch is already interacting with the joystick, have this touch move the joystick. If it doesn't show up over the joystick, maybe it hits a button, or touches the screen where there are no buttons and you should raycast to see what gameobject they are tapping!
Good luck!
Thanks for the answer and yes, i saw this solution when i searching, but i couldn't figure out if the first touch is on joystick object and after that there are some fire touches on the ground, or the first touch for firing on the ground and the second one is on the joystick for move action. How could i know which one i should track for move?
//For the first condition i should track =>
Input.GetTouches(0);
//For the second condition i should track =>
Input.GetTouches(1);
So, there can be some other conditions, too. Now, my problem is; how can i know for all conditions which touch is on the joystick and how to distinguish it from the others for move action?
Your answer
Follow this Question
Related Questions
Unusual multitouch behavior (Android) 3 Answers
How to get multitouch input using EasyTouch 0 Answers
Multi-touch for camera not working? 0 Answers
Multitouch problem 0 Answers
Simultaneous Multitouch Sends The Touch Over and Over 1 Answer