Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active December 13, 2018 15:34
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 unitycoder/10805d820bea9f78259e to your computer and use it in GitHub Desktop.
Save unitycoder/10805d820bea9f78259e to your computer and use it in GitHub Desktop.
Init UI button as selected
using UnityEngine;
using UnityEngine.UI;
// makes button selected at Start (to force Highlighted color on it)
// this is required to allow pressing Fire / Submit key to press button (without having to select button first)
public class InitButton : MonoBehaviour
{
void Start ()
{
if (GetComponent<Button>())
{
GetComponent<Button>().Select();
Destroy(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment