Unlock game with provided password / serial key
Hi. I want to unlock a mobile game with provided password / serial key. Below is the script that i used. I want to make the game unlocked using one password for one device. But i do not know how..
public void GetInput (string guess) {
if ((guess == "pass122") ||(guess == "pass133"))
{
Application.LoadLevel("Eat");
}
else if (guess == "")
{
OutputText.text = "Please enter your key";
}
else
{
OutputText.text = "Wrong key";
}
Answer by akisrn · Oct 27, 2016 at 01:50 AM
You're not calling your function anywhere so you it wouldn't really work. Also, all GUIs should be called inside the OnGUI function. I modified your code a little. I've tested this one and it works fine with me. Let me know how it will go. xx
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public string levelCode;
public bool isBlank;
public bool isWrongKey;
void OnGUI()
{
levelCode = GUI.TextField(new Rect(100, 100, 250, 30), levelCode);
GUI.Label(new Rect(200, 60, 300, 40), "Enter Level");
if (GUI.Button(new Rect(100, 140, 250, 30), "OK!"))
{
GetInput(levelCode);
}
if(isBlank)
{
GUI.Label(new Rect(200, 200, 300, 40), "Invalid Key!");
}
if(isWrongKey)
{
GUI.Label(new Rect(200, 200, 300, 40), "Wrong Key!");
}
}
public void GetInput (string guess)
{
if ((guess == "pass122") ||(guess == "pass133"))
{
Application.LoadLevel("Eat");
isBlank = false;
isWrongKey = false;
//Debug.Log("Load level Eat");
}
else if (guess == "")
{
isBlank = true;
isWrongKey = false;
Debug.Log("Invalid Key!");
}
else
{
isWrongKey = true;
isBlank = false;
Debug.Log("Wrong Key!");
}
}
}
Thanks @akisrn. It works fine. But as i mentioned earlier, i want to make the game unlocked using one time password for one device. Similar concept as activation code for an application.
@nurul-shuhadah maybe you can store the password in PlayerPrefs. Something like PlayerPrefs.SetString("myPassword", myPassword); where myPassword is where your password is stored. Then, at the start function, you can use something like if (PlayerPrefs.Has$$anonymous$$ey("myPassword") { //load level } else { // do what needs to be done if user hasnt saved the password }
Your answer

Follow this Question
Related Questions
How to set up a password to be used in the password input field? 1 Answer
Input Field Problem 0 Answers
Unity UI InputField can't type Chinese in iOS by speed dial type keyboard 1 Answer
how to make inputfield "*" asterisk without drawing GUI? 0 Answers
How to have rich text in an input field? 0 Answers