先登录功能,注册功能照猫画虎。
1.给两个inputFiled的Text add tag,通过tag获取两个输入框内容的代码如下。
using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using UnityEngine.UI;
using TMPro;
using System;
using Unity.VisualScripting;
public class RegPanelScript : MonoBehaviour {
//public UILabel accountLabel;
//public UILabel passwordLabel;
//public InputField inputField;
void Start () {
gameObject.SetActive (false);//加载时隐藏注册panel
//gameObject.SetActive(false);
}
public void Open()//主界面右边注册
{
gameObject.SetActive(true);
}
public void Close()//panel退出
{
gameObject.SetActive(false);
}
public void Exit()//红按钮退出
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;//在Unity编译器中结束运行
#else
Application.Quit();//在可执行程序中结束运行
#endif
}
public void LoginClick()//登录按钮
{
//先find,tag的效率更高-给input filed的text添加标签
TMP_Text a = GameObject.FindWithTag("username").GetComponent<TMP_Text>(); ;//得到两个Text对象
TMP_Text b = GameObject.FindWithTag("password").GetComponent<TMP_Text>(); ;//
Debug.Log("有戏!");
string username = a.text;
string password = b.text;
Debug.Log(username);//纯试出来的
Debug.Log(password);
//判断是否为空
//发送给服务器 sendmessage
}
}