Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active December 13, 2018 15:34
Show Gist options
  • Select an option

  • Save unitycoder/10805d820bea9f78259e to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/10805d820bea9f78259e to your computer and use it in GitHub Desktop.

Revisions

  1. unitycoder revised this gist Dec 13, 2018. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions InitButton.cs
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,17 @@
    using UnityEngine;
    using System.Collections;
    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 ()
    {
    // now you can press fire on xbox controller to select this button
    GetComponent<Button>().Select();
    Destroy(this);
    }

    if (GetComponent<Button>())
    {
    GetComponent<Button>().Select();
    Destroy(this);
    }
    }
    }
  2. unitycoder created this gist Aug 8, 2015.
    15 changes: 15 additions & 0 deletions InitButton.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;

    public class InitButton : MonoBehaviour
    {

    void Start ()
    {
    // now you can press fire on xbox controller to select this button
    GetComponent<Button>().Select();
    Destroy(this);
    }

    }