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,找到名称匹配的 foreach (InputField inputField in allInputFields) { if (inputField.gameObject.name == inputFieldName) // 替换为你的 InputField 名称 { return inputField; } } return null; } } }