Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using System;
- using System.IO;
- public class loginScript : MonoBehaviour {
- public Text name;// login tab for username
- public Text pw; // login tab for password
- public Text createName; // create account tab username
- public Text createPw; // create account tab password
- public GameObject wrongUserOrPass;
- public GameObject noUsername;
- public GameObject noPassword;
- public GameObject pressSubmit;
- //hide submit part
- public GameObject textCreateAcc;
- public GameObject textUsername;
- public GameObject textPassword;
- public GameObject inputFieldUsername;
- public GameObject inputFieldPassword;
- public GameObject submitButton;
- public GameObject submitSuccessful;
- public void Start()
- {
- wrongUserOrPass.SetActive(false);
- noUsername.SetActive(false);
- noPassword.SetActive(false);
- pressSubmit.SetActive(false);
- submitSuccessful.SetActive(false);
- }
- public void SubmitButton()
- {
- if(System.IO.File.Exists("C:/gameloginDATAUser.txt") == false)
- {
- string createUsername = createName.text.ToString();
- string createPassword = createPw.text.ToString();
- //put info in file
- if (string.IsNullOrEmpty(createUsername) && string.IsNullOrEmpty(createUsername))
- {
- }
- else
- {
- System.IO.File.WriteAllText("C:/gameloginDATAUser.txt", createUsername);
- System.IO.File.WriteAllText("C:/gameloginDATAPass.txt", createPassword);
- submitSuccessful.SetActive(false);
- }
- }
- }
- public void LoginButton()
- {
- string userName = name.text.ToString();
- string password = pw.text.ToString();
- //read info from file
- string usernameReadFromFile = File.ReadAllText("C:/gameloginDATAUser.txt");
- string PasswordReadFromFile = File.ReadAllText("C:/gameloginDATAPass.txt");
- if (string.IsNullOrEmpty(userName))
- {
- Debug.Log("ERROR | No content in username tab");
- wrongUserOrPass.SetActive(false);
- noUsername.SetActive(true);
- noPassword.SetActive(false);
- pressSubmit.SetActive(false);
- submitSuccessful.SetActive(false);
- return;
- }
- if (string.IsNullOrEmpty(password))
- {
- Debug.Log("ERROR | No content in password tab");
- wrongUserOrPass.SetActive(false);
- noUsername.SetActive(false);
- noPassword.SetActive(true);
- pressSubmit.SetActive(false);
- submitSuccessful.SetActive(false);
- return;
- }
- if (string.Equals(userName, usernameReadFromFile) && string.Equals(password, PasswordReadFromFile))
- {
- SceneManager.LoadScene("mainMenu");
- wrongUserOrPass.SetActive(false);
- noUsername.SetActive(false);
- noPassword.SetActive(false);
- pressSubmit.SetActive(false);
- }
- else
- {
- Debug.Log("ERROR | Wrong username or password");
- wrongUserOrPass.SetActive(true);
- noUsername.SetActive(false);
- noPassword.SetActive(false);
- submitSuccessful.SetActive(false);
- }
- if (System.IO.File.Exists("C:/gameloginDATAUser.txt") && System.IO.File.Exists("C:/gameloginDATAPass.txt"))
- {
- }
- else
- {
- pressSubmit.SetActive(true);
- wrongUserOrPass.SetActive(false);
- noUsername.SetActive(false);
- noPassword.SetActive(false);
- submitSuccessful.SetActive(false);
- Debug.Log("ERROR | Username file not found!");
- }
- }
- public void QuitButton()
- {
- Application.Quit();
- }
- public void RemoveFile()
- {
- File.Delete("C:/gameloginDATAUser.txt");
- File.Delete("C:/gameloginDATAPass.txt");
- }
- public void Update()
- {
- if (System.IO.File.Exists("C:/gameloginDATAUser.txt") && System.IO.File.Exists("C:/gameloginDATAPass.txt"))
- {
- textCreateAcc.SetActive(false);
- textUsername.SetActive(false);
- textPassword.SetActive(false);
- inputFieldUsername.SetActive(false);
- inputFieldPassword.SetActive(false);
- submitButton.SetActive(false);
- }
- else
- {
- textCreateAcc.SetActive(true);
- textUsername.SetActive(true);
- textPassword.SetActive(true);
- inputFieldUsername.SetActive(true);
- inputFieldPassword.SetActive(true);
- submitButton.SetActive(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement