Skip to content

Instantly share code, notes, and snippets.

@phosphoer
Created March 3, 2022 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phosphoer/ed2f31986f50adfbbfdc138e702eba8d to your computer and use it in GitHub Desktop.
Save phosphoer/ed2f31986f50adfbbfdc138e702eba8d to your computer and use it in GitHub Desktop.
Prevent Deselection Focus
using UnityEngine;
using UnityEngine.EventSystems;
public class PreventDeselectionGroup : MonoBehaviour
{
private EventSystem evt;
private GameObject sel;
private void Start()
{
evt = EventSystem.current;
}
private void Update()
{
if (evt.currentSelectedGameObject != null && evt.currentSelectedGameObject != sel)
sel = evt.currentSelectedGameObject;
else if (sel != null && evt.currentSelectedGameObject == null)
evt.SetSelectedGameObject(sel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment