• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by nurul-shuhadah · Oct 26, 2016 at 02:26 PM · inputfieldpasswordfield

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";
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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 t$$anonymous$$s 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!");
      }
 }
 
 }
 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nurul-shuhadah · Oct 27, 2016 at 03:56 AM 0
Share

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.

avatar image akisrn · Oct 27, 2016 at 09:27 AM 0
Share

@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.HasKey("myPassword") { //load level } else { // do what needs to be done if user hasnt saved the password }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set up a password to be used in the password input field? 1 Answer

Access gameobject from a different scene... 1 Answer

How do i convert inputfield input to float ? 0 Answers

Is there a way to set the mass of a gameobject without using the Rigidbody component?? 2 Answers

The UI Button Hitbox changes after using a Input Field on Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges