I’m built a virtual scuba dive game for use on touchscreen (single touch) and I’m having a nasty snag with touch interaction.
The project is pretty much finished and works fine with mouse/keys.
The problem is that when you touch the screen on a GUI button or a raycast to a collider to ‘touch’ a creature, the system appears to receive the click followed by the mouse position. If I double click, everything works fine → The first click event happens at the old position which updates the mouse position and so the system then knows where the mouse position is for the second click.
I think I need to kind of delay the click event till the mouse position is updated or re-trigger a simulated click at the updated position after the initial click.
It may be particular to this touchscreen - a NextWindow one.
Sorry if this is rambling - hope someone understands and knows a way round this…
Cheers,
Rob
the issue is that the touch screen likely is in touch screen mode while unity only supports mice.
So it expects the mouse to report delta positions for movement updates.
on a touch if you don’t touch it, it won’t update its position, it will do so on the first touch …
if the driver of it works right its driver then should send a mouse position update and the click … thats commonly the case when such devices offer a “mouse mode”
alternatively you could use a unmanaged plugin with unity pro and get the positioning and touch events right from the touch screen assuming they offer such libs (is commonly the case unless they are desktop screen oriented in which case they are opted and targeted at applications that support tablet support which unity does not)
Thanks for the reply!
Is there anyway to get unity to trigger a mouse click event?
I’m thinking quick fix as time is running out!!
Rob
But you can work around it.
Just add a boolean “clicked” that you set to true when you get a move which has a too large delta.
the Event class and filtering the corresponding EventTypes should get you going.
Unhappily you can not inject new events at least as far as I’m aware (the editor can do it so I’m pretty confident that there might be some undocumented functionality for it though)
Had the same problem.
My solution for the moment is: instead if getting the value back from if(GUI.Button) I grab the Event.MouseDown and check the position of the mouse against the rect of the button with rect.Contains(Event.current.mousePosition).
It works fine, but the over/down states on buttons get mixed up - I believe however that I should be able to fix it with a appropriate GUIStyle.