Unity makes login function 01-creates login UI and gets input content

 1. Create UI panel

Import plugin TextMesh Pro 

2. Write a script to obtain user input

The input box listening function is used here. All UIs can use the listening function. It should be noted that the TMP_InputField class is a plug-in TextMesh Pro imported into the UI! You need to reference the using TMPro; namespace in your code!

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEditor;
using System;
//该脚本1.获取场景中输入框组件2.获取用户输入内容
public class LOginUIControl : MonoBehaviour
{
     string UserAccount;
     string UserPassWord;
    public TMP_InputField InputAccount;
    public TMP_InputField InputPassWord;

    void Start()
    {
        InputAccount.onEndEdit.AddListener(OnUserInputAccount);

        InputPassWord.onEndEdit.AddListener(OnUserInputPassWord);

    }//end start

    private void OnUserInputPassWord(string userPassWord)
    {
        UserPassWord = userPassWord;
        Debug.Log("UserPassWord:"+ UserPassWord);
    }



    private void OnUserInputAccount(string Account)
    {
        UserAccount = Account;
        Debug.Log("UserAccount:" + UserAccount);
    }  

  

}//end class

 

Guess you like

Origin blog.csdn.net/leoysq/article/details/133273565