| 123456789101112131415161718192021222324 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace GFGGame
- {
- public static class UGUIHelper
- {
- public static InputField GetInputFieldByName(this GameObject gameObject, string inputFieldName)
- {
- InputField[] allInputFields = gameObject.GetComponentsInChildren<InputField>();
- // 遍历所有 InputField,找到名称匹配的
- foreach (InputField inputField in allInputFields)
- {
- if (inputField.gameObject.name == inputFieldName) // 替换为你的 InputField 名称
- {
- return inputField;
- }
- }
- return null;
- }
- }
- }
|