Created
March 3, 2022 20:23
-
-
Save phosphoer/ed2f31986f50adfbbfdc138e702eba8d to your computer and use it in GitHub Desktop.
Prevent Deselection Focus
This file contains 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; | |
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