• 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
Question by grimreaperpt · Mar 03, 2014 at 11:47 PM · textboxgui.labeltext box

How do I create a text box to display scrollable text I send it via script?

I'm currently making a game where I want to display text to describe what's happening. How can I send text to a text box without erasing the previous text, making it scroll up? Something like an in-game console where I could just print text on specific actions. Also, how could I erase "old" text (text that has been "scrolled up" x times)? Here's what I'm doing (I'm still learning how to code), and I realized I'm starting to run out of space :p

 function OnGui () {
 
 if (money < 15)    
 {
 GUI.Label (Rect(10,260,200,200), "You have no money to buy food");
 }
 
 if (actionsPerDay == 0)
 {
 GUI.Label (Rect(10,280,400,200), "You're tired and need to go to sleep");
 }
 
 if (hunger == 0)
 {
 GUI.Label (Rect(10,300,400,200), "You're starving! You need to eat urgently!");
 }
 
 }
Comment

People who like this

0 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 getyour411 · Mar 04, 2014 at 12:15 AM 0
Share

FYI, it is OnGUI (capitalization is important)

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by getyour411 · Mar 03, 2014 at 11:48 PM

http://answers.unity3d.com/questions/508268/i-want-to-create-an-in-game-log-which-will-print-a.html

An example in C# which uses a Queue instead of List:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
  
  
 public class playerLog : MonoBehaviour {
  
 public int maxLines = 8;
 private Queue<string> queue = new Queue<string>();
 private string Mytext = "";
  
 public void NewMessage(string message) {
 if (queue.Count >= maxLines)
 queue.Dequeue();
  
 queue.Enqueue(message);
  
 Mytext = "";
 foreach (string st in queue)
 Mytext = Mytext + st + "\n";
 }
  
  
 void OnGUI() {
  
 GUI.Label(new Rect(5, // x, left offset
 (Screen.height - 150), // y, bottom offset
 300f, // width
 150f), Mytext,GUI.skin.textArea); // height, text, Skin features}
 }


You could then use a GetComponent and pass messages to playerLog.NewMessage(newMessage), or declare that bit static so all classes can pass things to it w/o GetComponent references, etc.

Comment
omidprosper

People who like this

1 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 grimreaperpt · Mar 04, 2014 at 02:23 PM 0
Share

Cool, that thread was what I was looking for! Thank you!

avatar image getyour411 · Mar 06, 2014 at 01:01 AM 0
Share

yw; if you happen to see this, please tick the Accept Solution below the thumbs.

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

21 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

Related Questions

Resize scrollview height to match size of box inside 0 Answers

Rotated multi-coloured text 1 Answer

How to I allow a user to enter their name in a text box and show it in another level? 1 Answer

2 instances of text with different colors using OnGUI() and GUI.Label? 2 Answers

Textboxes and server side storage 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