Skip to content

Instantly share code, notes, and snippets.

View FerdieQO's full-sized avatar

Ferdie Swinkels FerdieQO

  • Geld.nl
  • Netherlands
View GitHub Profile
@FerdieQO
FerdieQO / ForceUIElementToBeSelectedComponent.cs
Last active March 15, 2022 09:15
Unity - Force to always have a UI/Canvas element selected
// This MonoBehaviour makes sure that you always have a Canvas element selected.
// By default, whenever you click anywhere on the screen that is not a Selectable, the
// currently selected GameObject will be set to null and nothing will be selected.
// Add this component to the EventSystem GameObject and enjoy :)
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UICodeExample.Code.UI