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

How to read and write txt from my file .txt

Discussion in 'Scripting' started by youness12345, Jul 2, 2019.

  1. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    welcome
    Please send me pictures showing how I can read and write in the user interface and save it in a .txt file
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    This is a c# question and not really Unity. Look at the documentation for
    Code (CSharp):
    1. using System.IO.TextWriter;
    There are tons of examples online how to use the textWriter and Reader to write and read to a text file.
     
    Joe-Censored and Antypodish like this.
  3. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    Can you please help me
     
  4. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    You need to be more specific what you want to do.
     
  5. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    I want to copy texts that are written in the file .txt and read
     
  6. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    I just need a quick UI in Unity to display text from 3 txt files saved in my pc, as well to save specific text back .
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Antypodish likes this.
  8. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    Can you send them to me as pictures please
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    I don't even know what "send them as pictures" means. Do you want screenshots of the documentation?

    If you want something you don't need to read because you just don't like reading, then boy do I have an upsetting fact for you about literally all programming.
     
    Joe-Censored likes this.
  10. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    welcome
    Is there a whole project?
    It has these specifications
    Thanks
     
  11. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    welcome

    Is there a whole project?
    It has these specifications
    Thanks
     
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    Lets try bite problem from different direction ...
    What did you try by yourself so far?
    Show us code, at which point you stuck.
    You will get help, as long you will show some commitment. But so far, you just ask only for freebees, even so you been given all you need.

    And as @chubbspet suggested, you really need work on your searching skill first.
     
    Joe-Censored likes this.
  13. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    welcome
    I just wanted to know how I can.
    I add a quick UI in the module to display the text of 3 txt files saved in my computer, as well as to save the selected text again.
     
  14. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    Show us something, what you tried and what doesn't work.
     
  15. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    You added this text
    I did not know how I could make him write
    In the input field and convert it to a file .txt
     
  16. youness12345

    youness12345

    Joined:
    Jan 6, 2019
    Posts:
    11
    using UnityEngine;
    using System.Collections;

    public class NewBehaviourScript : MonoBehaviour {
    public string txtFile = "test";
    string txtContents;
    // Use this for initialization
    void Start () {
    TextAsset txtAssets = (TextAsset)Resources.Load(txtFile);
    txtContents = txtAssets.text;

    }

    // Update is called once per frame
    void OnGUI () {
    GUILayout.Label (txtContents);

    }
    }
     
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    No one is going to craft images of documentation or tutorials simply because you prefer that medium. If you need to be spoon fed everything, you aren't going to be successful making games since this is really easy stuff compared to most of the problems you will encounter in your projects.

    There does not exist a ready made project which does exactly what you want since what you're asking for is rather unusual for a game. It is pretty trivial code and trivial UI work, but not something that most games would implement.
     
  18. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You can read from a text file like that, but you're not going to be able to write to a text file that is in a Resources folder. Also, OnGUI is for the legacy UI. You should follow some tutorials for the current UI which was implemented back in Unity 4.6, or tutorials for TextMeshPro which is a free package from Unity for the past few years.