UGUI按Tab键切换输入框

2023-04-24,,

脚本挂在输入框的父物体上即可

[code]csharpcode:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; public class CutInput : MonoBehaviour {
private EventSystem system;
//输入框集合
private InputField[] inputArray;
// Use this for initialization
void Start () {
system = EventSystem.current;
inputArray = this.GetComponentsInChildren<InputField>();
}
int index = 0;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Tab))
{
if (index>=inputArray.Length)
index = 0; system.SetSelectedGameObject(inputArray[index].gameObject,new BaseEventData(system));
index++;
}
}
}

  

UGUI按Tab键切换输入框的相关教程结束。

《UGUI按Tab键切换输入框.doc》

下载本文的Word格式文档,以方便收藏与打印。