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 LinkUpGames · May 09, 2014 at 01:16 AM · javascriptguiguilayout.button

How to Get a Login Function to Work Locally?

So I am making this program for my Dad to use at work so he can take Inventory on Items and a few other things. What I want to do is create a Login system that doesn't use network functionality it just checks if the fields are correct and loads the program. Currently what I have seems to work for getting the correct Login but I cannot get it to detect an incorrect Login. My current Script looks like this. var userToEdit : String; var passwordToEdit : String; var customSkin : GUISkin; var correctLogin : boolean = false;

 function Start () {
 
 }
 
 function Update () 
 {
     if(userToEdit == "User" && passwordToEdit == "password")
         {
             correctLogin = true;
         }
     else
         {
             correctLogin = false;
         }
 }
 
 function OnGUI ()
 {
 GUI.skin = customSkin;
 
     userToEdit = GUI.TextField(Rect (Screen.width/ 2 - 50,Screen.height/2,200,20), userToEdit, 25);
 
     passwordToEdit = GUI.PasswordField(Rect (Screen.width/2 - 50,Screen.height/2 + 25,200,20), passwordToEdit, "*"[0], 25);
     
     if(GUILayout.Button("Login", "button") && correctLogin == true)
     {
         Debug.Log("This Button Works!");
     }
     else
     {
         Debug.Log("Login Failure");
     }
     
 }

Originally there wasn't a boolean but I added it to see if it would work better to no avail. What I think is the issue is that the Button I create isn't a permanent object and I cannot reference it outside of that one line of code. How can I make it so if the User and Password are incorrect and I click the Login button it will display "Incorrect Login" in the Debug Log? Any help will be very much appreciated :)

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

Answer by Maerig · May 09, 2014 at 02:43 AM

 if(GUILayout.Button("Login", "button"))
 {
     if(correctLogin)
     {
         Debug.Log("This Button Works!");
     }
     else
     {
         Debug.Log("Login Failure");
     }
 }
Comment
Add comment · Show 1 · 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 LinkUpGames · May 09, 2014 at 02:49 AM 0
Share

I feel really stupid now, but thank you very much for the help xD I guess it serves me right for staying up so late trying to do this!

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

21 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

Related Questions

How do I change the text of a gui image text 1 Answer

NGUI Repeat button In JavaScript problem 1 Answer

GuiTexture Width Change 1 Answer

Setting Scroll View Width GUILayout 1 Answer

facebook with unity problem 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