• 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
Question by robertmathew · Mar 25, 2011 at 12:46 PM · textfieldpasswordfield

password filed and text field

in GUI.TextArea and GUI.PasswordField i am using gui.textarea as user name field and GUI.passwordField as password field .my need is i want to set a common user name and password for the user as as username-user and password-admin. it is the login screen when the player before entering the game should have to enter the user name and password i want to set the common password and username when the user enter the correct password and user name set in the script then only login button should enabled. if the user enter password- admin and username -user then only the login button should enabled other wise it should remain login button as disable condition.i want to set user name - user and password- admin as common for all user. with out entering the this user name and password the login button should not enabled

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Scribe · Mar 25, 2011 at 04:59 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){
         GUI.Button(Rect(75, 60, 50, 20),"Login");
     }
 }

}

put this on your camera, you can change the password and username by changing the desired variables

hope this helps

Scribe

Comment
robertmathew
Lo0NuhtiK

People who like this

2 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 · Mar 28, 2011 at 05:37 AM 0
Share

thanks a lot for the answer

avatar image Scribe · Mar 28, 2011 at 02:48 PM 0
Share

You're welcome glad I could be of some help

avatar image
Best Answer

Answer by Statement · Mar 25, 2011 at 05:02 PM

var btnColorOn : Color = Color(1.0f, 1.0f, 1.0f, 1.0f); var btnColorOff : Color = Color(0.4f, 0.4f, 0.4f, 1.0f);

private var btnColor = btnColorOff; private var username : String = String.Empty; private var password : String = String.Empty; private var correctLogin : boolean;

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

 var speed = Time.deltaTime * 4;
 var targetColor = correctLogin ? btnColorOn : btnColorOff;

 btnColor.r = Mathf.MoveTowards(btnColor.r, targetColor.r, speed); 
 btnColor.g = Mathf.MoveTowards(btnColor.g, targetColor.g, speed); 
 btnColor.b = Mathf.MoveTowards(btnColor.b, targetColor.b, speed); 
 btnColor.a = Mathf.MoveTowards(btnColor.a, targetColor.a, speed); 

}

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) { // Add your login code here... enabled = false; } GUI.color = Color.white; }

Comment
robertmathew
Lo0NuhtiK

People who like this

2 Show 0 · 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.

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

1 Person is following this question.

avatar image

Related Questions

gui text and password field 1 Answer

TextFields Android issue: switching between different fields it copies the string 0 Answers

Text fields where text will scale along with resolution. 1 Answer

Clear text field and allow user to return to keyboard control 1 Answer

Maximum number of letters in textfield 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