Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by josifjoey · Apr 05, 2011 at 03:29 PM · javascriptstringpassword

why doesn't this script work

Im trying to make a password system that loads a level

var passwordToEdit : String = "My Password";

 var LevelTovLoad : String;



private var OneTowTreeFour : String;

 function OnGUI () 

 {

     passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);



     if(passwordToEdit == OneTowTreeFour)

     {

         Application.LoadLevel(LevelTovLoad);

     }

 }

please help me iv really wanted to no this for a while now

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AVividLight · Apr 05, 2011 at 03:40 PM

I think that you need to change you script to:

var passwordToEdit : String = "My Password"; var correctPassword : String = "OneTowTreeFour"; var levelToLoad : int = 0;

 function OnGUI () {
     passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);

     if(passwordToEdit == correctPassword) {    
         Application.LoadLevel(levelToLoad);    
     }    
 }

Besides rearranging your code, I changed your "LevelTovLoad" to "levelToLoad" and made it an intager instead of a string, so that you only have to put in one number. I changed the Private Variable "OneTowTreeFour" to a Public Variable called "correctPassword" and made OneTowTreeFour into the answer...

Oh, one more thing, if you want some of those really good "coder-people" to answer (or even read) your question, you should use descriptive questions, and try your best to explain your problem... Anyway, I hope I helped!

Comment
Add comment · 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
0

Answer by robertmathew · Apr 05, 2011 at 03:34 PM

var desiredUsername = "user"; var stringToEdit = ""; var desiredPassword = "admin"; var passwordToEdit = "";

   function OnGUI () {

// Make a multiline text area that modifies stringToEdit. GUI.Label(Rect (10, 10, 60, 20), "Username: "); GUI.Label(Rect (10, 35, 60, 20), "Password: ");

  stringToEdit = GUI.TextField (Rect (75, 10, 200, 20), stringToEdit, 200);

  passwordToEdit = GUI.PasswordField (Rect (75, 35, 200, 20), passwordToEdit, "*"[0], 25);

 if(stringToEdit == desiredUsername)
       {
 if(passwordToEdit == desiredPassword)
       {
     Application.LoadLevel(LevelTovLoad);
       }
       }
       }

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 robertmathew · Apr 05, 2011 at 03:38 PM 1
Share

here the user name is user and password is ad$$anonymous$$ when u enter the correct password and user name defined var as desiredUsername and desiredPassword you will go to levelToLoad

avatar image josifjoey · Apr 05, 2011 at 03:43 PM 0
Share

thanks :) big time

avatar image
0

Answer by robertmathew · Apr 05, 2011 at 03:45 PM

private var correctLogin : boolean;

    function Update()
           {
    correctLogin = (username == "user" && password == "admin");
           }


     function OnGUI()
        {
   var windowRect : Rect;
   windowRect.x = Screen.width / 2 - 100;
   windowRect.y = Screen.height / 2 - 50;
   windowRect.width = 200;
   windowRect.height = 100;

 GUI.Window(0, windowRect, OnWindowGUI, "Authentication");
       }

function OnWindowGUI() { username = GUILayout.TextField(username); password = GUILayout.PasswordField(password, '*'[0]); GUI.color = btnColor; if (GUILayout.Button("Login") && correctLogin) { Application.LoadLevel(LevelTovLoad);

       }

       }

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How can i split a string[] ? 1 Answer

Javascript - Calling a random String 2 Answers

String Problem in Java Script 1 Answer

Combo Script Problem 1 Answer

How you can start the animation of an object as finished another ? 0 Answers


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