Skip to content

Instantly share code, notes, and snippets.

@maikelcoke
Last active May 8, 2018 11:49
Show Gist options
  • Save maikelcoke/00886fe975d45b318a8a8e404dd6981a to your computer and use it in GitHub Desktop.
Save maikelcoke/00886fe975d45b318a8a8e404dd6981a to your computer and use it in GitHub Desktop.
GUITab.cs: Form tab functionallity
// Create a GUITab.cs and attach it to e.g. your Canvas:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class GUITab : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
if (Input.GetKey(KeyCode.LeftShift))
{
if (EventSystem.current.currentSelectedGameObject != null)
{
Selectable selectable = EventSystem.current.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnUp();
if (selectable != null)
selectable.Select();
}
}
else
{
if (EventSystem.current.currentSelectedGameObject != null)
{
Selectable selectable = EventSystem.current.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnDown();
if (selectable != null)
selectable.Select();
}
}
}
}
}
//You can now tab through fields. Its not perfect, but I think you get the idea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment