Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using UnityEngine.SceneManagement;
  5. using System;
  6. using System.IO;
  7.     public class loginScript : MonoBehaviour {
  8.     public  Text name;// login tab for username
  9.     public  Text pw; // login tab for password
  10.     public Text createName; // create account tab username
  11.     public Text createPw; // create account tab password
  12.     public GameObject wrongUserOrPass;
  13.     public GameObject noUsername;
  14.     public GameObject noPassword;
  15.     public GameObject pressSubmit;
  16.     //hide submit part
  17.     public GameObject textCreateAcc;
  18.     public GameObject textUsername;
  19.     public GameObject textPassword;
  20.     public GameObject inputFieldUsername;
  21.     public GameObject inputFieldPassword;
  22.     public GameObject submitButton;
  23.     public GameObject submitSuccessful;
  24.     public void Start()
  25.     {
  26.         wrongUserOrPass.SetActive(false);
  27.         noUsername.SetActive(false);
  28.         noPassword.SetActive(false);
  29.         pressSubmit.SetActive(false);
  30.         submitSuccessful.SetActive(false);
  31.  
  32.     }
  33.     public void SubmitButton()
  34.     {
  35.             if(System.IO.File.Exists("C:/gameloginDATAUser.txt") == false)
  36.          {
  37.             string createUsername = createName.text.ToString();
  38.             string createPassword = createPw.text.ToString();
  39.             //put info in file
  40.             if (string.IsNullOrEmpty(createUsername) && string.IsNullOrEmpty(createUsername))
  41.             {
  42.             }
  43.             else
  44.             {          
  45.                     System.IO.File.WriteAllText("C:/gameloginDATAUser.txt", createUsername);
  46.                     System.IO.File.WriteAllText("C:/gameloginDATAPass.txt", createPassword);
  47.                     submitSuccessful.SetActive(false);
  48.             }
  49.            
  50.  
  51.         }
  52.            
  53.     }
  54.  
  55.     public void LoginButton()
  56.     {
  57.         string userName = name.text.ToString();
  58.         string password = pw.text.ToString();
  59.         //read info from file
  60.         string usernameReadFromFile = File.ReadAllText("C:/gameloginDATAUser.txt");
  61.         string PasswordReadFromFile = File.ReadAllText("C:/gameloginDATAPass.txt");
  62.         if (string.IsNullOrEmpty(userName))
  63.         {
  64.             Debug.Log("ERROR | No content in username tab");
  65.             wrongUserOrPass.SetActive(false);
  66.             noUsername.SetActive(true);
  67.             noPassword.SetActive(false);
  68.             pressSubmit.SetActive(false);
  69.             submitSuccessful.SetActive(false);
  70.  
  71.             return;
  72.  
  73.         }
  74.         if (string.IsNullOrEmpty(password))
  75.         {
  76.             Debug.Log("ERROR | No content in password tab");
  77.             wrongUserOrPass.SetActive(false);
  78.             noUsername.SetActive(false);
  79.             noPassword.SetActive(true);
  80.             pressSubmit.SetActive(false);
  81.             submitSuccessful.SetActive(false);
  82.  
  83.             return;
  84.         }
  85.         if (string.Equals(userName, usernameReadFromFile) && string.Equals(password, PasswordReadFromFile))
  86.         {
  87.             SceneManager.LoadScene("mainMenu");
  88.             wrongUserOrPass.SetActive(false);
  89.             noUsername.SetActive(false);
  90.             noPassword.SetActive(false);
  91.             pressSubmit.SetActive(false);
  92.         }
  93.         else
  94.         {
  95.                Debug.Log("ERROR | Wrong username or password");
  96.             wrongUserOrPass.SetActive(true);
  97.             noUsername.SetActive(false);
  98.             noPassword.SetActive(false);
  99.             submitSuccessful.SetActive(false);
  100.  
  101.         }
  102.         if (System.IO.File.Exists("C:/gameloginDATAUser.txt") && System.IO.File.Exists("C:/gameloginDATAPass.txt"))
  103.         {
  104. }
  105.         else
  106.         {
  107.             pressSubmit.SetActive(true);
  108.             wrongUserOrPass.SetActive(false);
  109.             noUsername.SetActive(false);
  110.             noPassword.SetActive(false);
  111.             submitSuccessful.SetActive(false);
  112.  
  113.  
  114.             Debug.Log("ERROR | Username file not found!");
  115.         }
  116.     }
  117.     public void QuitButton()  
  118.     {
  119.         Application.Quit();
  120.     }
  121.     public void RemoveFile()
  122.     {
  123.         File.Delete("C:/gameloginDATAUser.txt");
  124.         File.Delete("C:/gameloginDATAPass.txt");
  125.     }
  126.     public void Update()
  127.     {
  128.         if (System.IO.File.Exists("C:/gameloginDATAUser.txt") && System.IO.File.Exists("C:/gameloginDATAPass.txt"))
  129.         {
  130.             textCreateAcc.SetActive(false);
  131.             textUsername.SetActive(false);
  132.             textPassword.SetActive(false);
  133.             inputFieldUsername.SetActive(false);
  134.             inputFieldPassword.SetActive(false);
  135.             submitButton.SetActive(false);
  136.         }
  137.         else
  138.         {
  139.             textCreateAcc.SetActive(true);
  140.             textUsername.SetActive(true);
  141.             textPassword.SetActive(true);
  142.             inputFieldUsername.SetActive(true);
  143.             inputFieldPassword.SetActive(true);
  144.             submitButton.SetActive(true);
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement