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 GoThXoRd¹ · Oct 23, 2014 at 06:28 AM · guistringdebuglog

How Do I Display Multiple Strings In Here?

This script pretty much makes a Debug/Chat log but it only displays one string at a time. How do i get it to print the next string underneath rather than overwrite the previous one?

 var stringToEdit : String = "";
 
 
 function OnGUI() {
 GUI.Label(Rect(10, Screen.height / 4*3.5, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
     }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dark_Tiger · Oct 23, 2014 at 06:33 AM

Increment the Y value after you write each string

 var stringToEdit : String = "";
  int y = Screen.height / 4*3.5;
  
  function OnGUI() 
      {
         GUI.Label(Rect(10, y, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
         y += Screen.height / 4*3.5;
      }

I'm a bit new to this, so I'm guessing that's where the y value is passed in for the label.

Comment
Add comment · Show 4 · 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 GoThXoRd¹ · Oct 23, 2014 at 06:36 AM 0
Share

I'm not sure what that means. This is set up so, rather than printing to the editor console, it displays the text in to onscreen box.

On another script that uses this:

 stringToEdit.stringToEdit = ("Picked up SpaceRocks");
avatar image Dark_Tiger · Oct 23, 2014 at 06:43 AM 0
Share

I'm not sure if what I did was right, I'm really a noob at this xD but that's the sort of logic you need to add, so you're increasing the y value each time you go through, that will display the message lower and lower.

avatar image GoThXoRd¹ · Oct 23, 2014 at 06:50 AM 0
Share

Yeah I could see your logic but I'm not sure if that would be the solution at this time. What I'm really looking for is a multi-lined text field that I can't edit or select. All it needs to do is display text sent to it and display the next lot of text sent to it on the next line, if that makes sense..

avatar image Dark_Tiger · Oct 23, 2014 at 07:43 AM 0
Share

I really don't know :L the guys below seem to know their stuff more

avatar image
0

Answer by fafase · Oct 23, 2014 at 06:59 AM

 var offsetY:float = 50f;
 function OnGUI() {
     for(var i:int = 0; i < amountOfString; i++){
         GUI.Label(Rect(10, (Screen.height / 4*3.5) + offsetY * i, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
     }
 }

offsetY is how much space you want between each writing. Then the y value of the printing gets the original place plus this offset times the i value.

So the first will get

  (Screen.height / 4*3.5) + offsetY * i -> i is 0
  (Screen.height / 4*3.5) + offsetY * i -> i is 1 so 50 
  (Screen.height / 4*3.5) + offsetY * i -> i is 2 so 100

and so on

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 · Oct 23, 2014 at 07:08 AM

As an alternate to placing multiple labels (which will work), you can take your collection of strings and build a single string that has a newline between each string.

 #pragma strict
             
 private var stringToEdit : String = "";
 private var chatLines : String[] = ["One", "Two", "Three", "Four", "Five", "Six"];
 
 function Start() {
     BuildText();
 }
  
  function OnGUI() {
      GUI.Label(Rect(10, Screen.height / 4*3.5, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
  }
 
 function BuildText() {
     stringToEdit = "";
     for (var i = 0; i < chatLines.Length; i++) {
         stringToEdit += chatLines[i] + "\n";
     }
 }

In this bit of sample code, chatLines would be the incoming chat lines. You would be updating this list each time a new line comes in and then calling BuildText. Attach this sample code to an empty game object and hit run.

Comment
Add comment · Show 1 · 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 fafase · Oct 23, 2014 at 07:53 AM 0
Share

I would say you have your answer in either this one or $$anonymous$$e. The goal would define which suits best. $$anonymous$$ine, I'd think, would be better for distinct and separate information that you want to space out. On the other end if it is a long sentence then you may go better with this one which will keep things closer together. On a side note on this one above, if your string gets to be real long, you may want to use a StringBuilder ins$$anonymous$$d if you were to do that often.

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

28 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

Related Questions

Simulating a Log 2 Answers

How do I change the logged text based on a momentary collision? 1 Answer

Debug.Log print order, or Awake vs Start issue? 1 Answer

Standalone save output_log 2 Answers

Problems with simple dialogue 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