• 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 RayneAvalon · Apr 11, 2013 at 02:12 AM · c#guitriggerpassword

How to make a Keypad for a locked door

So i have this project where i have to create a code locked door, and then have the player approach it and put in a password. If the password is correct then the door opens, and if not then the password field just resets.

 using UnityEngine;
 using System.Collections;
 
 public class KeyPad: MonoBehaviour {
 
     public Texture2D icon;
 
     void OnGUI () {
         GUI.Box (new Rect (10,10,300,300), new GUIContent(icon));
 
         
     }
     
 
 }

so far this is the only code i have finished and working, and even then i need to find a way to keep this hidden until the player passes through a trigger near the door. I have no coding skills and honestly dont understand coding much but this is something i have to do for a class. i would appreciate any and all help that could be offered.

Comment
Add comment · Show 9
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 robertbu · Apr 11, 2013 at 02:21 AM 0
Share

As your next step, play with GUI.Button() as one way to display the buttons for your keypad.

avatar image RayneAvalon · Apr 11, 2013 at 05:52 AM 0
Share

i am using a photoshop image as a keypad as per my instructions in the assignment. what i have to do now it put a password field into this so that the player can input a 5 digit password on the keyboard and then press enter. after that the password will be compared to a pre written one. if they match an animated door is activated and the key pad gui is deactivated, if they dont match then the password field just resets so they can try again. but without seeing the code to do these things specifically i cant really work with just the walkthrough stuff on the site. its just not how my brain works. please if anyone can provide me with examples of code that i could use. they dont even have to do specifically what i need just something i can build off of, like how to make a password field accept keyboard input, and or how to set its password and such. im a total novice and my $$anonymous$$cher is of little help.

avatar image Unitraxx · Apr 11, 2013 at 02:48 PM 0
Share

You should add this text as a comment to my answer. (Click more -> convert to comment.) As for your problem, it's not just solved in a few lines of code and we have nothing to start out with. Just try yourself, and if you get stuck come back. I don't think someone will completely write this for you.

avatar image robertbu · Apr 11, 2013 at 03:16 PM 0
Share

As @Unitraxx mentions, new information should not be entered as a comment to your original question or as an edit to your original question. Answers are for attempts to answer your question. Now your question is marked as having two answers and will therefore have far less traffic. You can convert this question to an answer using the "more" dropdown.

Given your new description, you need to look at either GUI.TextField() or GUI.PasswordField() depending on the specification in your assignment. After you have the field up and running, Google something "Unity3d GUI.Textfield Enter" to figure out how to capture the enter key. $$anonymous$$ake an attempt to code it yourself. If you get stuck, come back with your attempt.

avatar image RayneAvalon · Apr 11, 2013 at 06:37 PM 0
Share

alright after looking at the pages you guys recommended i have a decent update for my code. the password field appears where it needs to and receives input. There are only 2 things i have left to get working for this to be ready. i need to make it so that the gui only appears while a player is inside a certain trigger, and while i have code for capturing one of the return keys for some reason it doesnt seem to be working.

 using UnityEngine;
 using System.Collections;
 
 
 
 public class $$anonymous$$eyPad: $$anonymous$$onoBehaviour {
 
     public Texture2D icon;
     public string SetPassword = "12345";
     public string PlayerPassword = "";
     void OnGUI () {
         GUI.Box (new Rect (10,10,300,300), new GUIContent(icon));
         PlayerPassword = GUI.PasswordField (new Rect(60, 60, 200, 35), PlayerPassword, "*"[0],35);
         
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$eypadEnter))
         {  
             
             if(PlayerPassword == SetPassword)
             {
             transform.Translate(Vector3.left * 2 * Time.deltaTime);
             }
             
         }
         
     }
             
     
 
 }

i was thinking of using a GUI.Enable set up but i wouldn't know how to code a trigger for it since all the triggers i know work with game objects not scripts. oh and does anyone know how to change the text size in a password field?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Unitraxx · Apr 11, 2013 at 02:25 AM

Coding is a fun and useful skill to have, I suggest you just dig into some tutorials :) This GUI scripting guide is pretty useful and should get you started with your specific problem : http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html

Basically the callback of a button should append the number that button presents to a list (thus this list contains all buttons that are already pressed). You can then compare this list to your password to see if it's correct. :)

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 HelloDerr90 · Apr 12, 2013 at 05:11 AM

To get the GUI to pop up when you are near the door I would add a collider to the door. Script a trigger event that allows the GUI to open when you enter the collider and close the GUI when you exit the collider.

Then in your GUI I would add the GUI buttons and assign each button a number. The player than can input a code and your script can check to see if it is correct and then open the door if it is.

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 RayneAvalon · Apr 13, 2013 at 04:54 AM 0
Share

thank you for the advice, my current coding should cover all of that, and as per a previous comment i was told not to use buttons for input but the keyboard.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

How to make my OnTriggerEnter() and Exit work 1 Answer

How to Set Max Numbers for a password 2 Answers

Coin pickup script not working..? 1 Answer

Distribute terrain in zones 3 Answers

Factory script not working 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