• 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 KwixArc · Dec 10, 2016 at 07:40 AM · dooropen

Openable Door with Question

I'm currently making a game using Unity for an EAST project and my way of making it school ready is by making the game prompt the player with a grammatical question when they try opening a door with a key. I like this idea in theory, but I personally don't know how to accomplish this in Unity. For example, when the player walks up to a door with a key in their inventory and try to open the door, I want it to prompt the player with the text "I heard that there food is great, we should eat that instead." Then, it will ask the question "Correct this sentence." The player will then be prompted with the interface showing " needs to be changed to " The user will then be able to input "there" "their", thus filling the blanks with the answer. Upon doing this, the door should open for the player and allow them to go inside. I'm not fully sure if this function is even possible to do in Unity, but it's hypothetically a key feature for my project and any help with this issue would be greatly appreciated. Also it's any help, this is the code that I currently have in my game for the doors to be opened (the code is written in Java):

 var smooth = 2.0;
 var DoorOpenAngle = 90.0;
 private var open : boolean;
 private var enter : boolean;
 
 private var defaultRot : Vector3;
 private var openRot : Vector3;
 
 function Start(){
     defaultRot = transform.eulerAngles;
     openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
 }
 
 //Main function
 function Update (){
     if(open){
         //Open door
         transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
     }else{
         //Close door
         transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
     }
 
     if(Input.GetKeyDown("q") && enter){
         open = !open;
     }
 }
 
 function OnGUI(){
     if(enter){
         GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'Q' to open the door");
     }
 }
 
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
     if (other.gameObject.tag == "Player") {
         enter = true;
     }
 }
 
     //Deactivate the Main function when player is go away from door
     function OnTriggerExit (other : Collider){
         if (other.gameObject.tag == "Player") {
             enter = false;
         }
     }
Comment
Add comment · Show 1
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 AlwaysSunny · Dec 10, 2016 at 07:40 AM 0
Share

Allowing because you formatted your code and that makes us very happy around here. This kind of question is not generally allowed because the answers you need are only a half-hour of independent research away... But maybe another volunteer will help out. This can definitely be done, just to make that clear.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RobAnthem · Dec 10, 2016 at 08:22 AM

AlwaysSunny is right, but it is actually pretty easy, and to sum it up, this is what you need: 1. a GUI for the text to exist in, with a script that has usable string variable and bool for the event. 2. The door script that checks if the bool from the GUI is true. 3. the GUI asks question, compares string, then finds the door component, also might want to add a var to the door script to differentiate from different doors, and runs the open event.

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.

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

84 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assets/Scripts/Door.cs(25,69): error CS8032: Internal compiler error during parsing, Run with -v for details 1 Answer

text code to unlock door 2D 1 Answer

Question about triggers 2 Answers

Open Door Animation Problem 0 Answers

Open/Close Door only if player is near the Door 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