Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active May 11, 2020 20:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unitycoder/6cfbba6766eb74e3d3f8 to your computer and use it in GitHub Desktop.
Save unitycoder/6cfbba6766eb74e3d3f8 to your computer and use it in GitHub Desktop.
Ignore UI element from clicking
// 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;
}
}
}
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