• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
Question by shadowshad · Dec 01, 2013 at 09:27 AM · messages

Multiple Choice question to popup when pressing a key

Hello, this is my first post, and I m new to Unity, and i m doing a game for a class. The idea is when your near a door you would press "f" a question would pop up if you answer it right, the door will open if not a "try again" message would show. i have figured out the door opening part, but i m struggling with the question message when f is pressed. please help

here is the script P.S. the script been taking from different posts and reworked for my project.


  1. pragma strict

//Make an empty game object and call it "Door" //Rename your 3D door model to "Body" //Parent a "Body" object to "Door" //Make sure thet a "Door" object is in left down corner of "Body" object. The place where a Door Hinge need be //Add a box collider to "Door" object and make it much bigger then the "Body" model, mark it trigger //Assign this script to a "Door" game object that have box collider with trigger enabled //Press "f" to open the door and "g" to close the door //Make sure the main character is tagged "player"

// Smothly open a door var smooth = 1; var DoorOpenAngle = 90.0; var textToShow1: String; var textToShow2: String; var isQuestionaryOn = false;

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("f") && enter){ open = !open; } }

function OnGUI(){ if(enter){ GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'F' to open the door"); } } GUI.Label (Rect (20, 10, 500, 30), "we’re much better at a wide variety of behaviors when…"); GUI.Label (Rect (300, 40, 500, 600), textToShow1); GUI.Label (Rect (300, 70, 500, 600), textToShow2);

if(GUI.Button(Rect(20,40,250,20),"We’re thinking about them.")) { textToShow1="Try Again"; } if(GUI.Button(Rect(20,70,250,20),"We’re not thinking about them.")) { isQuestionaryOn=true; textToShow2="well done!"; }

}

//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

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

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

Multiple Cars not working 1 Answer

The infamous "NullReferenceException: Object reference not set to an instance of an object" error 1 Answer

Health Help D: 2 Answers

Help for basic board game but for me it's hard.. 0 Answers

Help with city building game? 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