Skip to content

Instantly share code, notes, and snippets.

@Cdddo
Last active September 6, 2022 18:37
Show Gist options
  • Save Cdddo/9c9a588e4afaabf891453e3e18accc0e to your computer and use it in GitHub Desktop.
Save Cdddo/9c9a588e4afaabf891453e3e18accc0e to your computer and use it in GitHub Desktop.
Auto Select On Enable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class SelectOnEnable : MonoBehaviour
{
void OnEnable()
{
// clear any selected objects
EventSystem.current.SetSelectedGameObject(null);
// set new selected object
EventSystem.current.SetSelectedGameObject(this.gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class SelectOnEnable : MonoBehaviour
{
void OnEnable()
{
// clear any selected objects
EventSystem.current.SetSelectedGameObject(null);
// set new selected object
EventSystem.current.SetSelectedGameObject(this.gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment