Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Ryan-Markwort · Apr 15, 2016 at 04:42 AM · c#scripting problemuitexttextbox

Unity 2D - Text UI and Textbox scripting issue - HELP ASAP!

Hi, I'm new to Unity, coding and game development. I was trying to make a textbox system, and something isn't working, and it's not allowing my .txt file lines to be written in the Text UI object. It's just displaying default text, and not displaying what I wanted... Please help? :)

I cannot figure out what is wrong... :(

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class TextBoxManager : MonoBehaviour {
 
     public GameObject textBox;
 
     public Text theText;
 
     public TextAsset textFile;
     public string[] textLines;
 
     public int currentLine;
     public int endAtLine;
 
     public PlayerController player;
 
     // Use this for initialization
     void Start () 
     {
         player = FindObjectOfType<PlayerController>();
 
         if (textFile != null) 
         {
             textLines = (textFile.text.Split('\n'));
 
         }
 
         if(endAtLine == 0) 
         {
             endAtLine = textLines.Length - 1;
 
         }
 
     }
 
     void update()
     {
 
         theText.text = textLines[currentLine];
 
         if (Input.GetKeyDown (KeyCode.Return)) 
         {
             currentLine += 1;
 
         }
     }
 }
text-1.png (226.0 kB)
text-2.png (190.5 kB)
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 $$anonymous$$ · Apr 15, 2016 at 06:55 AM

I would suggest some improvements of your code:

  • assign a start value to currentLine before you use it the first time

  • Add theText.text = textLines[currentLine] into the if statement. This avoids adding the text each frame

  • Use Input.GetKeyUp to avoid going through all the lines real quick when you are holding the return key to long down. I guess you want to move 1 further only ones per key push

  • add code to limit currentLine to the maximum number of lines available.

  • Use Update instead of update as it must be used with a capital U.

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 chetanmac · Apr 15, 2016 at 06:56 AM

Please refere this link: http://answers.unity3d.com/questions/279750/loading-data-from-a-txt-file-c.html I think it will solve your problem!

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problems in the script for making a text disappear after few seconds 2 Answers

Inspector changes set TextMeshPro values on play 1 Answer

What's your equivalent of old GUIStyle ? 0 Answers

Get Text from an Input Field on one scene and use it as a text on another scene Unity c# 0 Answers

How to measure the width of a string? 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