1. Create the UI (Button, Inputfield, etc.) that can be selected in the Hierarchy panel.
2. Create C # script Tabcutpichon on the canvas.
3. Write the script.
1 usingSystem.Collections;2 usingSystem.Collections.Generic;3 usingUnityengine;4 usingUnityengine.eventsystems;5 6 Public classTabcutpitchon:monobehaviour7 {8 //Get EventSystem Components9 PrivateEventSystem system;Ten //Dictionary: Key Game object number, game object One Privatedictionary<int,gameobject>dicobj; A //the index used to store the resulting dictionary - Private intindex; - the voidStart () - { - //Initialize Fields -system =eventsystem.current; +Dicobj =Newdictionary<int, gameobject> (); -index =0; + //assign a value to a dictionary A for(inti =0; i < Transform.childcount; i++) { at Dicobj.add (i, transform. Getchild (i). Gameobject); - } - //get the Game object in the dictionary corresponding to the index - Gameobject obj; -Dicobj.trygetvalue (Index, outobj); - //sets the first interactive UI to be highlighted inSystem. Setselectedgameobject (obj,NewBaseeventdata (System)); - } to + voidUpdate () - { the //when there is UI highlighting (get the highlighted UI, not empty) and press the TAB key * if(System.currentselectedgameobject! =NULL&&Input.getkeydown (Keycode.tab)) { $ //the UI object that gets the current highlighted statePanax NotoginsengGameobject hightedobj =System.currentselectedgameobject; - //look at the first few objects in the scene. the foreach(keyvaluepair<int,gameobject> Iteminchdicobj) { + if(item. Value = =hightedobj) { AIndex = Item. Key +1; the //index Zero is exceeded + if(Index = =dicobj.count) { -index =0; $ } $ Break; - } - } the //get the corresponding index of the game object - Gameobject obj;WuyiDicobj.trygetvalue (Index, outobj); the //make the resulting game object highlight -System. Setselectedgameobject (obj,NewBaseeventdata (System)); Wu } - } About}
TAB key Toggle Input box, button (tab to toggle highlighted UI) in Unity