using UnityEngine;
using System.Collections;
public class SetNextControlName : MonoBehaviour
{
public string login = "";
public string login2 = "";
private int countOfUserArea = 0 ;
private int countOfPasswordArea = 0 ;
void OnGUI()
{
// target 1 将被以"user"监视
GUI.SetNextControlName("user");
login = GUI.TextField(new Rect(10, 10, 130, 20), login); // target 1
// target 2 将被以"password"监视
GUI.SetNextControlName("password");
login2 = GUI.TextField(new Rect(10, 40, 130, 20), login2); // target 2
if (GUI.GetNameOfFocusedControl() == "user")
{
Debug.Log("UserName: " + countOfUserArea.ToString()) ;
++countOfUserArea ;
}
else if (GUI.GetNameOfFocusedControl() == "password")
{
Debug.Log("Password: " + countOfPasswordArea.ToString()) ;
++countOfPasswordArea ;
}
if (GUI.Button(new Rect(150, 10, 50, 20), "Login"))
{
Debug.Log("Login");
}
}
}
SetNextControlName&GetNameOfFocusedControl
最新推荐文章于 2021-01-13 14:31:23 发布