unity学习(6)——通过button获取inputField的内容

先登录功能,注册功能照猫画虎。

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
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值