Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active May 11, 2020 20:18
Show Gist options
  • Select an option

  • Save unitycoder/6cfbba6766eb74e3d3f8 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/6cfbba6766eb74e3d3f8 to your computer and use it in GitHub Desktop.

Revisions

  1. unitycoder revised this gist May 26, 2019. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions FixMouseClicksForUI.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // 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;
    }
    }
    }
  2. unitycoder created this gist May 3, 2015.
    11 changes: 11 additions & 0 deletions UIIgnoreRaycast.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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;
    }
    }