74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class InitSceneScirpt : MonoBehaviour
|
|
{
|
|
private Button loginbtn;
|
|
private TMP_InputField accountInputField;
|
|
private TMP_InputField passwordInputField;
|
|
public string GameScene;
|
|
|
|
public Image TipPlane;
|
|
|
|
public void Init()
|
|
{
|
|
loginbtn = GameObject.Find("LoginBtn").GetComponent<Button>();
|
|
accountInputField = GameObject.Find("account").GetComponent<TMP_InputField>();
|
|
passwordInputField = GameObject.Find("password").GetComponent<TMP_InputField>();
|
|
|
|
}
|
|
void Start()
|
|
{
|
|
Init();
|
|
loginbtn.onClick.AddListener(() =>
|
|
{
|
|
OnLoginButtonClicked();
|
|
});
|
|
}
|
|
public void OnLoginButtonClicked()
|
|
{
|
|
if (accountInputField != null && passwordInputField != null)
|
|
{
|
|
string inputAccount = accountInputField.text;
|
|
string inputPassword = passwordInputField.text;
|
|
|
|
Debug.Log("输入的账号: " + inputAccount);
|
|
Debug.Log("输入的密码: " + inputPassword);
|
|
|
|
|
|
if ((inputAccount == "taosuqi" && inputPassword == "123") || (inputAccount == "wangchun" && inputPassword == "321"))
|
|
{
|
|
LoadGameScene(GameScene);
|
|
Debug.Log("输入正确,登录成功");
|
|
//loginResultText.text = "登录成功!";
|
|
}
|
|
else
|
|
{
|
|
TipPlane.gameObject.SetActive(true);
|
|
Debug.Log("账号或密码错误,请重新输入");
|
|
//loginResultText.text = "账号或密码错误,请重新输入!";
|
|
}
|
|
|
|
}
|
|
else if (accountInputField == null)
|
|
{
|
|
Debug.Log(accountInputField + "为空");
|
|
}
|
|
else if (passwordInputField == null)
|
|
{
|
|
Debug.Log(passwordInputField + "为空");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 记载场景
|
|
/// </summary>
|
|
private void LoadGameScene(string GameScene)
|
|
{
|
|
SceneManager.LoadScene(GameScene);
|
|
Debug.Log("跳转到游戏场景");
|
|
}
|
|
}
|