hi everyone! i watched the live session about how to make a simple joystick on mobile,and i got a problem.
OK,firstly,this is my Canvas which contains three image ui elment


and then i attach a script to my “movementZone” UI image to detect the direction to move,and the script just like this:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class MySimpleJoyStick : MonoBehaviour ,IPointerUpHandler,IPointerDownHandler,IDragHandler{
private Vector2 origin;
private Vector2 direction;
private int pointerID;
private bool touched;
void Awake(){
direction = Vector2.zero;
touched = false;
}
public void OnPointerDown(PointerEventData data){
if(!touched){
touched = true;
origin = data.position;
pointerID = data.pointerId;
}
}
public void OnDrag(PointerEventData data){
if(data.pointerId==this.pointerID){
Vector2 currentPosition = data.position;
Vector2 directionRaw = currentPosition - origin;
direction = directionRaw.normalized;
}
}
public void OnPointerUp(PointerEventData data){
if(data.pointerId==pointerID){
direction = Vector2.zero;
touched = false;
}
}
public Vector2 GetDirection(){
return direction;
}
}
the problem is that when i first finger touched and moved whthin the area of the movement zone ,it works fine.
however when i put another finger on my screen, it will affect my movement.
that’s stranger,becase i already use pointerid to make sure only one finger will be effectively.
thanks you guys in advanced!!![]()