Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Last active October 12, 2022 17:07
Show Gist options
  • Save kurtdekker/501489d3ea837ec245cb89f6369c70d9 to your computer and use it in GitHub Desktop.
Save kurtdekker/501489d3ea837ec245cb89f6369c70d9 to your computer and use it in GitHub Desktop.
Overlay input-blocking facility for Unity3D (input / click blocker / inhibitor)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker
//
// Purpose:
// - to inhibit processing of input whenever a popup is enabled
//
// To use:
// - place one of these somewhere in any and all popup windows you make
//
// - in code, query OverlayBlocker.ShouldAllowInput to decide if you need to process clicks
//
public class OverlayBlocker : MonoBehaviour
{
public static bool ShouldAllowInput
{
get
{
return counter == 0;
}
}
static int counter;
void OnEnable()
{
counter++;
}
void OnDisable()
{
counter--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment