Hi,
I'm using Camera2DDrag on touch mode (single tap/click). When swiping (i.e. dragging the camera around), if I start swiping from a position where a hotspot is located, the hotspot examine action is triggered.
How can I avoid this? Maybe by activating hotspots only on mouse up?
Comments
When using Touch Screen input, there's an option in the Settings Manager named Activate Hotspots with double-tap?. There isn't such an option for tap/mouse-release, though you could add an input override that would cause mouse/tap releases to work like clicks.
See this tutorial, but note that the mouse button delegate you want instead is named InputGetMouseButtonDownDelegate. A similar script could be used to override this delegate, so that mouse up events work as mouse down events.
The second issue is to allow the camera dragging to work when the mouse is over a Hotspot. This is checked for specifically in PlayerInput, around line 1630:
if (!KickStarter.playerInteraction.IsMouseOverHotspot ())
{
dragState = DragState._Camera;
if (deltaDragMouse.magnitude * Time.deltaTime <= 1f && (GetInvertedMouse () - dragStartPosition).magnitude < 10f)
{
dragState = DragState.None;
}
}
Here the code is only allowing the camera to be dragged if the cursor is not over a Hotspot. You could allow this by removing the check:
dragState = DragState._Camera;
if (deltaDragMouse.magnitude * Time.deltaTime <= 1f && (GetInvertedMouse () - dragStartPosition).magnitude < 10f)
{
dragState = DragState.None;
}
Alternatively, you could attach a custom camera dragging script instead - see Section 4.6 in the Manual.
if (button == 0)
{
return Input.GetMouseButtonUp (0))
}
return Input.GetMouseButtonDown (button);
It may be that instead you'll get a better result by modifying PlayerInteraction.cs instead. This is the script that actually performs the interaction based on the mouse state - the PlayerInput script merely reads those mouse states in the first place. In PlayerInteraction, you can find multiple references to MouseState.SingleClick - if you change them to MouseState.LetGo, the Hotspots should instead react to mouse releases.