Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TStringList in C#

Discussion in 'Scripting' started by miguelandrade, Mar 28, 2015.

  1. miguelandrade

    miguelandrade

    Joined:
    Feb 28, 2015
    Posts:
    22
    Hello,

    My code is working:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.IO;
    5. using System;
    6. using System.Text;
    7.  
    8.  
    9.  
    10. public class GuiTeste : MonoBehaviour {
    11.  
    12.  
    13.     public string result1;
    14.     public string result2;
    15.     public string result3;
    16.  
    17.  
    18.  
    19.     void OnGUI()
    20.     {
    21.  
    22.  
    23.  
    24.         GUILayout.BeginHorizontal();
    25.  
    26.  
    27.         GUI.Label (new Rect (60,20,90,50), result1.ToString());
    28.         GUI.Label (new Rect (60,30,90,50), result2.ToString());
    29.         GUI.Label (new Rect (60,50,90,50), result3.ToString());
    30.  
    31.         GUILayout.EndHorizontal();
    32.  
    33.  
    34.         GUILayout.BeginArea (new Rect (200, 200, 150, 250));
    35.  
    36.  
    37.         GUILayout.BeginHorizontal();
    38.  
    39.         GUILayout.Label ("Teste");
    40.  
    41.         GUILayout.EndHorizontal();
    42.  
    43.  
    44.  
    45.         GUILayout.BeginHorizontal();
    46.      
    47.         if(GUI.Button(new Rect(20,20,80,30),"Start Game"))
    48.         {
    49.          
    50.             //Application.Quit ();
    51.  
    52.             string[] lines = { "First line", "Second line", "Third line" };
    53.             //string[] lines2;
    54.  
    55.             System.IO.File.WriteAllLines(@"WriteLines.txt", lines);
    56.  
    57.             string [] aaa = File.ReadAllLines(@"WriteLines.txt");
    58.  
    59.             result1 = aaa[0];
    60.             result2 = aaa[1];
    61.             result3 = aaa[2];
    62.  
    63.  
    64.         }
    65.      
    66.         GUILayout.EndHorizontal();
    67.  
    68.  
    69.  
    70.         GUILayout.BeginHorizontal();
    71.                               //left top width height
    72.         if(GUI.Button(new Rect(20,80,80,30),"Exit"))
    73.         {
    74.          
    75.             Application.Quit ();
    76.          
    77.         }
    78.      
    79.         GUILayout.EndHorizontal();
    80.  
    81.  
    82.  
    83.  
    84.  
    85.         GUILayout.EndArea();
    86.  
    87.  
    88.  
    89.  
    90.     }
    91.  
    92. }
    93.  
    94.  
    The question is... why appear this warning on Unity Editor?

    Type '[Assembly-CSharp]GuiTeste' has an extra field 'result1' of type 'System.String' in the player and thus can't be serialized
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

    Type '[Assembly-CSharp]GuiTeste' has an extra field 'result2' of type 'System.String' in the player and thus can't be serialized
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()


    Type '[Assembly-CSharp]GuiTeste' has an extra field 'result3' of type 'System.String' in the player and thus can't be serialized
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
     
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Try removing "using System;", you are not using it anyway.
     
  3. miguelandrade

    miguelandrade

    Joined:
    Feb 28, 2015
    Posts:
    22
    seens thats working!!! thank you...