• 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 isaiastheweezerd · Dec 12, 2017 at 01:09 AM · advicetext box

Simple text box, directions?

In the 3D game i am currently working on, (First person), i want the player to walk up to an NPC ( i have them out in the map) press a button, and have a text box appear, with text. Then another press of the button and the text box is gone.

I am wondering if anyone could point me in directions for where i could get a tutorial on this specific thing, (Or advice when making the scripts for this to happen.)

Thank you.

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 pako · Dec 15, 2017 at 07:27 PM 0
Share

https://unity3d.com/learn/tutorials/s/user-interface-ui

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ElijahShadbolt · Dec 15, 2017 at 08:53 PM

You can use the Unity UI system and EventSystems coupled with some custom scripting to create this logic.


GameObject > UI > Text - this will create a new Text element (along with a UI Canvas and EventSystem) and you can edit the displayed text (and change it dynamically with its text property).


Position UI elements with the RectTransform tool found in the Toolbar. In the Scene view, drag the Text element inside the (very large) Canvas rect so you can see it in Play mode.


Create a custom script (C#) - in the Insepctor > Add Component > New Script - give it a name, e.g. MessageBox. Then click the new component's gear icon > Edit


In the new MonoBehaviour class add the following code:

     public UnityEngine.UI.Text textbox;

     void Update()
     {
         // if player presses 'E' key this frame
         if (Input.GetKeyDown(KeyCode.E))
         {
             // if textbox reference exists
             if (textbox != null)
             {
                 // toggle textbox (visible/hidden)
                 bool wasActive = textbox.gameObject.activeSelf;
                 textbox.gameObject.SetActive(!wasActive);
             }
         }
     }


In the Inspector of the MessageBox component, assign a reference to the Text element by dragging it from the hierarchy into the Textbox property of the MessageBox component.


For more information, Google is your friend.

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 Daniel-Talis · Dec 12, 2017 at 06:30 AM

You may need either a 'dialogue system' or a 'notification system'.

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

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

73 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

Related Questions

Compositing a cursor over a rendertexture - GL pipeline problems? 0 Answers

Looking to learn. 2 Answers

How do I remove this text box 1 Answer

Need advice for C# Freelance-Work 1 Answer

Advice needed: good ways to implement networking into turn-based card game 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