From 19dca7e5556fddf607d027e9a0bf927a85f25acc Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 22 Mar 2016 13:11:44 +0000 Subject: [PATCH] Fixed Clickable sprites can be clicked through UI objects #377 --- Assets/Fungus/Sprite/Scripts/Clickable2D.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs index 6b76ea14..a12265b7 100644 --- a/Assets/Fungus/Sprite/Scripts/Clickable2D.cs +++ b/Assets/Fungus/Sprite/Scripts/Clickable2D.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.Events; +using UnityEngine.EventSystems; using System.Collections; namespace Fungus @@ -24,6 +25,11 @@ namespace Fungus return; } + if (EventSystem.current.IsPointerOverGameObject()) + { + return; // Ignore this mouse event, pointer is over UI + } + // TODO: Cache these object for faster lookup ObjectClicked[] handlers = GameObject.FindObjectsOfType(); foreach (ObjectClicked handler in handlers) @@ -34,11 +40,17 @@ namespace Fungus protected virtual void OnMouseEnter() { + if (EventSystem.current.IsPointerOverGameObject()) + { + return; // Ignore this mouse event, pointer is over UI + } + changeCursor(hoverCursor); } protected virtual void OnMouseExit() { + // Always reset the mouse cursor to be on the safe side SetMouseCursor.ResetMouseCursor(); }