Unity Login Registration Page Data delivery (no database)

Source: Internet
Author: User

Unity Login Registration Page Data delivery (no database)

Following an essay. Create the Unity Login Registration page.

Create a script:

new Script "Goa" (store global variables for easy invocation of other scripts):

Using Unityengine;
Using System.Collections;

public class Goa:monobehaviour {

//user name
Public Const String name = "M_name";
//Password
Public Const string Password = "M_password";

}

new Script "Btn_loadscene" (for scene jumps):

Using Unityengine;
Using System.Collections;
Using Unityengine.ui;
Using System.Collections;


public class Btn_loadscene:monobehaviour {

public string Loadscenename; // defines a scene name string for a jump scene

void OnMouseUp () //mouse click Invoke, Trigger button event

{
Invoke ("Jump", 0.5F); //0.5 seconds Call "Jump" method

}

void Jump ()

{

Application.loadlevel (Loadscenename); //Jump Scene (scene name can be modified externally)

}

}

new Script "Loadin" (for login judgment) and a jump to register the scene:

Using Unityengine;
Using System.Collections;
Using Unityengine.ui;

public class Loagin:goa//Note that the global variable "Goa" that the script has just created is used here

{
//Tick box
Public Toggle rempasswd;
Private Toggle fogpasswd;

//Registration Information
Public Inputfield InputName;
Public Inputfield inputpaswd;



//Jump Scene name
public string loadscenename;//This does not require this line of code


//gui Tip Information
Public Text Ui_massage;
private string Stringmassage;

void Update ()
{

Ui_massage.text = Stringmassage;

//If the Remember password is checked
if (Rempasswd.ison)
{
//Fill data
Inputpaswd.text =inputpaswd.text.trim ();
}
Else
{
Inputpaswd.text = Inputpaswd.text;
}


}

void OnCLick ()
{
String name = InputName.text.Trim ();
String oldname = Playerprefs.getstring (goa.name);

string password = InputPaswd.text.Trim ();
String OldPassword = Playerprefs.getstring (Goa.password);

//user name passwordInput Judgment
if (string. IsNullOrEmpty (name)) {

Print (stringmassage= "message: Please enter a nickname");
Return
}
if (string. IsNullOrEmpty (password)) {

Print (stringmassage= "message: Please enter password");
Return
}

if (oldname! = InputName.text.Trim () | | Oldpassword!=inputpaswd.text.trim ()) {

Print (stringmassage= "message: User name or password error");
Return
}


//user name password is correct jump scene
Print (stringmassage= "message: Login successful");
Application.loadlevel ("1");//Jump to Scene 1


}

void Regist ()
{

//print (stringmassage= "message: Registration successful");
Application.loadlevel ("register");//Jump to registration scenario

}
}

new Script "register" (registration page)

Using Unityengine;
Using System.Collections;
Using Unityengine.ui;

public class Register:goa//Note that the global variable "Goa" that the script has just created is used here
{


//Registration Information
Public Inputfield InputName;
Public Inputfield inputpaswd;
Public Inputfield inputPaswd2;



//Jump Scene name
public string Loadscenename;


//gui Tip Information
Public Text Ui_massage;
private string Stringmassage;

void Update ()
{

Ui_massage.text = Stringmassage;


}

void OnCLick ()
{
String name = InputName.text.Trim ();
string password = InputPaswd.text.Trim ();
String password2 = InputPaswd2.text.Trim ();


//user name password is correct jump scene
if (string. IsNullOrEmpty (name)) {

Print (stringmassage= "message: Please enter a nickname");
Return
}
if (string. IsNullOrEmpty (password) | | InputPaswd.text.Length! = 8) {

Print (stringmassage= "message: Please enter 8-digit password");
Return
}
if (string. IsNullOrEmpty (Password2)) {

Print (stringmassage= "message: Please enter the confirmation password");
Return
}
if (password! = password2) {

Print (stringmassage= "message: two times password entered incorrectly");
Return
}

Playerprefs.setstring (Goa.name,name);
Playerprefs.setstring (Goa.password,password);
Print (stringmassage= "message: Registration successful");
Application.loadlevel (Loadscenename);
}

void Returntoload ()
{

Application.loadlevel ("Load");

}


}

go back to the login scenario "load".

Assign the script "loagin" to the camera.

Click the button event Plus, add a button event, drag the camera to the button carrier, select the script "Loadin" under the

"send Message (string)". In the input box that appears, enter a method in the script used by the login button. The method name is the same as the script method name.

Using the same procedure, select the Register button, adjust the properties of the Click event,

load all the required jumps into the Build setting .

Run the logon scenario. (self-test according to required)

Because the first test, no account password, so the input is not jump scene.

Enter the registration screen

Assign the script "register" to the camera as you have just described.

Drag into an instantiated object

Follow the sign-in button of the login screen and choose the button to return to login. Drag the script to the jump scene to set properties:

Follow the sign-in interface of the login button making method, select the Registration button method setting properties as follows:

All right. Now the production is done.

Run. Normal!

(If there is an error, you can contact me)

Unity Login Registration Page Data delivery (no database)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.