Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

How to display from txt an specific line to GUI?

Discussion in 'Scripting' started by pauloaguiar, Jul 30, 2014.

  1. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    I need help on txt so far I have a small piece of code found in the answer section.
    It works fine, but I do not know the correct location to show a specific line of text in the GUI.
    How to display GUI 1 line 2 line or element 0, element 1, etc. ...

    Any idea?

    code :
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. import System;
    4. import System.IO;
    5. import System.Collections.Generic;
    6. import System.Linq;
    7.  
    8. var fileLines : List.<String>;
    9.  
    10. function Start () {
    11.  
    12.     ReadFile();
    13. }
    14. function ReadFile()
    15. {
    16.      var sr = File.OpenText("Test.txt");
    17.      fileLines = sr.ReadToEnd().Split("\n"[0]).ToList();
    18.      sr.Close();  
    19. }
    20. function OnGUI ()
    21. {
    22.      GUI.Label(Rect(10,150,150,150),"?");
    23. }
     
    Last edited: Jul 30, 2014
  2. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Any chance?
     
  3. MysteriX

    MysteriX

    Joined:
    Apr 8, 2014
    Posts:
    54
    Hi,
    I don´t know if I understand your last Sentence right but you can get the elements of the Array by this code (please have a look at line 19):

    Code (CSharp):
    1. #pragma strict
    2. import System;
    3. import System.IO;
    4. import System.Collections.Generic;
    5. import System.Linq;
    6. var fileLines : List.<String>;
    7. function Start () {
    8.     ReadFile();
    9. }
    10. function ReadFile()
    11. {
    12.      var sr = File.OpenText("Test.txt");
    13.      fileLines = sr.ReadToEnd().Split("\n"[0]).ToList();
    14.      sr.Close();
    15.  
    16. }
    17. function OnGUI ()
    18. {
    19.      GUI.Label(Rect(10,150,150,150),fileLines[0]);
    20.  
    21. }
     
  4. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    :eek: that simple:oops: hehe:p

    My aim is to create characters dialogue simply by calling the respective line of text in a text file for each situation.
    I pity after export to exe, txt file is not visible. Well I would like the user can modify to translate into your language.

    Do not know if it's a good way.
    In other words is STR style.

    For example:

    Mission 1.

    P1: Hey, how's it going?
    P2: You'll be walking. What have you been doing?
    P1: Nothing special.

    Mission 2.

    P1: Your mission is to escape as far as possible.
    P2: I'll try my best possible.
    P1: Do not trust anybody. A lot of fake people.

    I add some staff to have access to the line number .

    Code (JavaScript):
    1. var linetextNumber : int = 0;
    modify.
    Code (JavaScript):
    1. GUI.Label(Rect(10,150,150,150),fileLines[linetextNumber]);
     
  5. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    It is possible to read the name without relying on P1?
    I mean show the name but not the P1.
    The P1 serves only as a reference.
     
  6. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    It is possible to read the name without relying on P1?
    like:

    P1> My text.
    Read "my text" and not "P1>".?
     
    Last edited: Aug 1, 2014
  7. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    I know how to make the text stand pending the executable. So you can modify the text to other languages freely.

    But I still need help how to manipulate paragraph, without counting the P1?? manipulating spaces.
     
  8. GregMeach

    GregMeach

    Joined:
    Dec 5, 2012
    Posts:
    249
  9. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    i´m not pro in c#:( how to apply?? sorry for asking.
     
  10. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    this is cool:

    var arrLine : String[] = File.ReadAllLines(fileName);
    arrLine[line_to_edit - 1] = newText;
    File.WriteAllLines(fileName, arrLine);