Last active
May 11, 2020 20:18
-
-
Save unitycoder/6cfbba6766eb74e3d3f8 to your computer and use it in GitHub Desktop.
Ignore UI element from clicking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ignore mouse clicks for UI | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
public class FixMouseClicksForUI : MonoBehaviour | |
{ | |
GameObject lastselect; | |
void Start() | |
{ | |
lastselect = new GameObject(); | |
} | |
void Update() | |
{ | |
if (EventSystem.current.currentSelectedGameObject == null) | |
{ | |
EventSystem.current.SetSelectedGameObject(lastselect); | |
} | |
else | |
{ | |
lastselect = EventSystem.current.currentSelectedGameObject; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// http://answers.unity3d.com/questions/816861/46-ui-image-is-capturing-clicks-how-to-prevent.html | |
public class UIIgnoreRaycast : MonoBehaviour, ICanvasRaycastFilter | |
{ | |
public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment