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 fir3st0rm9 · Jan 25, 2013 at 08:33 PM · guirpgtextareadialog

I am trying to make an RPG style dialog script

So I am making a script where there is a text area at the bottom of the screen and every time you click it displays the next message. Here is my code

 var DialogText = new Array();
 
 private var number = 0;
 
 function Start () {
 
     DialogText.length = 19;
 
 }
 
 function Update () {
 
 }
 
 
 
 function OnGUI () {
      if (Input.GetButton("Fire1")) {
          GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
          number += 1;
      }
 }



The problem I am running into is that when I attach it to my camera to use it, I can't edit the DialogText variable in the unity editor. I also have a problem that there is no text being displayed.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AT-Brackeys · Jan 26, 2013 at 01:48 AM

To simply get it to show in the editor, all you have to do is this :)

 var DialogText = new String[19];
  
 private var number = 0;
  
 function OnGUI () {
      if (Input.GetButton("Fire1")) {
        GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
        number += 1;
      }
 }
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 robertbu · Jan 26, 2013 at 02:54 AM

I'm guessing about your intent. Try restructuring your code to this:

 function OnGUI () {
     GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
      if (Input.GetButtonDown("Fire1")) {
          number += 1;
      }
 }

First, I replaced your GetButton() with GetButtonDown() That way number will only be increment during the frame the "Fire1" button is pressed. In addition I pulled GUI.TextArea() call outside of your if statement.

Comment
Add comment · Show 2 · 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 fir3st0rm9 · Jan 26, 2013 at 08:10 AM 0
Share

Okay, this works great except for one part. I want after 11 messages go by, for a text box to appear so the user can input their name. How would I go about doing this so that the textarea is cleared from the screen and replaced with a textfield until the user presses enter and then the info inserted into the text field is stored in a variable then the messages will reappear at the next number (12).

(Sorry if this is super confusing, I'm working on a big project right now and my brain is overloaded and tired :P)

avatar image robertbu · Jan 26, 2013 at 01:50 PM 0
Share

OnGUI gets executed each frame, so your GUI.TextArea() is gettting put up each frame. If you don't make the TextArea() call, then the text won't be displayed. As for an edit field, I believe you are looking for GUI.TextField(). You may also want to put up a submit button at the same time (GUI.Button).

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

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

RPG turns system - arranging turns freezes up 1 Answer

How to make a cutscene like RPG Games 1 Answer

Prevent IOS keyboard from showing 0 Answers

Toolbar Selection 0 Answers

GUI Text field? How do I make the text so it goes on more then one line? 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