Last active
May 8, 2018 11:49
-
-
Save maikelcoke/00886fe975d45b318a8a8e404dd6981a to your computer and use it in GitHub Desktop.
GUITab.cs: Form tab functionallity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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