- Home /
Issue with Multi Touch Screens.
I am currently working on a project which is using three touch sensors with two displays. I am having an issue with mapping the touches to the correct display.
This diagram shows the desired mapping:
So to do this I am using this:
void Update () {
Debug.Log(Input.touchCount);
for (int i = 0; i < Input.touches.Length; i++)
{
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
}
}
}
The issue is that every touch to any sensor is showing on Display1. I believe this is down to: Camera.main.ScreenPointToRay(touch.position);
But I cant find a way to detect which screen is being touched to use the correct camera. Is there a way around this issue?
Answer by Zytronic_Touch · Jan 19, 2018 at 12:10 PM
This works for the unity editor, it needs to be changed to work with the player for whatever OS you are using. It returns a Vector3 where the z index is the displayID.
public static Vector3 DebugRelativeMouseAt()
{
var mouseOverWindow = EditorWindow.mouseOverWindow;
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
Type type = assembly.GetType("UnityEditor.GameView");
int displayID = 0;
if (type.IsInstanceOfType(mouseOverWindow))
{
var displayField = type.GetField("m_TargetDisplay", BindingFlags.NonPublic | BindingFlags.Instance);
displayID = (int)displayField.GetValue(mouseOverWindow);
}
var pos = Input.mousePosition;
pos[2] = displayID;
return pos;
}
Answer by hantouan · Jan 26, 2018 at 11:42 AM
I have a similar issue with my app. I m using 4 different cameras to display on 4 touchscreens. On each touchscreen i have a canvas and I need to use touch event to pan/zoom the content on each canvas. However I always get the touch on every single canvas, and only on the actual canvas touched.
I haven't found any solution yet.,
Answer by joshstiemsma · Sep 13, 2018 at 03:24 PM
wow im in the same exact boat! two touch monitors and it seams like i can hit buttons on the canvas of the second screen but my touch.position is always on the first screen
Your answer
Follow this Question
Related Questions
Multi-Display - Multi Touch Screen Issues 0 Answers
Two view and Two function for the Mouse Cursor 1 Answer
how to Screen.SetResolution() for 2nd monitor/multiple monitor 0 Answers
Android multiple display 0 Answers
Windows 7 Multitouch limits 0 Answers