- Home /
Question by
ninofrenn · Mar 17, 2021 at 01:44 PM ·
inputmultitouch
Handle Multitouch on Mobile with Joystick
Hello, i can't get it on my mind. I'm working on android fps game. I have custom controller with input touch to rotate player attached camera, and a simple joystick to make player move forward backward etc. What am i currently struggling is how to switch wether the touch is for joystick or outta it. This is my code.
if (Input.touchCount > 0) {
for(int i = 0; i < Input.touchCount; i++) {
Touch touch = Input.GetTouch(i);
switch (touch.phase) {
case TouchPhase.Began:
if(isJoystickTouch(touch.position)) return;
if(indexTouch == -1)//if empty
indexTouch = i;
startPos = touch.position;
direction = Vector2.zero;
lastVert = playerCamera.localEulerAngles.x;
lastHor = character.localEulerAngles.y;
Debug.Log("touch");
break;
case TouchPhase.Moved:
if(indexTouch == i) {
direction = touch.position - startPos;
}
break;
case TouchPhase.Ended:
if(indexTouch == i)
indexTouch = -1;//reset
break;
}
}
}
The problem with that code is, whenever the index of touch is change. Touch moved won't work. Any idea?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613030834im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
EventSystem - Broadcast my own Input 1 Answer
Multi-touch randomly breaks on WP8 when not plugged in to PC 0 Answers
four simultaneous touch inputs in android 2 Answers
Problem with multi-touch from android 1 Answer
iPhone input multitouch 1 Answer