| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class Login : MonoBehaviour {
- public GameObject username;
- public GameObject password;
- public Button loginButton;
- public Text errorText;
- private string Username;
- private string Password;
- private string loginUrl = "http://nordh.xyz/narKampen/dbFiles/Login.php?";
- private void Start() {
- loginButton.onClick.AddListener(loginAction);
- }
- private void Update() {
- Username = username.GetComponent<InputField>().text;
- Password = password.GetComponent<InputField>().text;
- }
- void loginAction() {
- string errorMessage = "";
- if (Username == "") {
- errorMessage = "Username is required";
- }
- if (Password == "") {
- if (errorMessage != "") {
- errorMessage += "\n";
- }
- errorMessage += "Password is required";
- }
- Color errorColor = errorText.color;
- if (errorMessage == "") {
- errorColor.a = 0;
- StartCoroutine(loginCall());
- } else {
- errorText.text = errorMessage;
- errorColor.a = 1;
- }
- errorText.color = errorColor;
- }
- IEnumerator loginCall() {
- string postUrl = loginUrl + "name=" + UnityWebRequest.EscapeURL(Username) + "&password=" + UnityWebRequest.EscapeURL(Password);
- UnityWebRequest www = UnityWebRequest.Get(postUrl);
- yield return www.SendWebRequest();
- if (www.error != null) {
- errorText.text = "There was an error logging in " + www.error;
- }
- }
- }
|