Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity read from text file

using UnityEngine;
using UnityEditor;
using System.IO;

public class HandleTextFile
{
    [MenuItem("Tools/Write file")]
    static void WriteString()
    {
        string path = "Assets/Resources/test.txt";

        //Write some text to the test.txt file
        StreamWriter writer = new StreamWriter(path, true);
        writer.WriteLine("Test");
        writer.Close();

        //Re-import the file to update the reference in the editor
        AssetDatabase.ImportAsset(path); 
        TextAsset asset = Resources.Load("test");

        //Print the text from the file
        Debug.Log(asset.text);
    }

    [MenuItem("Tools/Read file")]
    static void ReadString()
    {
        string path = "Assets/Resources/test.txt";

        //Read the text from directly from the test.txt file
        StreamReader reader = new StreamReader(path); 
        Debug.Log(reader.ReadToEnd());
        reader.Close();
    }

}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity access phone camera 
Csharp :: how to join array indexes with comma in c# 
Csharp :: c# string to byte array 
Csharp :: c# stringbuilder to file 
Csharp :: .net core add header to soap request 
Csharp :: c# create instance from type 
Csharp :: c# convert string to enum value 
Csharp :: readonly vs const c# 
Csharp :: Specified key was too long; max key length is 1000 bytes (SQL: alter table `permissions` add unique `permissions name guard_name_unique`(`name`, `guard_name`)) 
Csharp :: DateTime previous day c# 
Csharp :: bubble sort in c# 
Csharp :: c# datagridview change column name 
Csharp :: c# how to check if two lists have same values 
Csharp :: ggdesign 
Csharp :: C# Console multi language 
Csharp :: google sheets sum if check contains string 
Csharp :: merge point 
Csharp :: unity clamp rotation 
Csharp :: c# for loop increment by 2 
Csharp :: unity look at target 
Csharp :: C# How to write Hello World 
Csharp :: unity hide mesh 
Csharp :: How to get an array of months in c# 
Csharp :: c# get all the column names from datagridview 
Csharp :: enum get all values c# 
Csharp :: c# string array to string 
Csharp :: increase timeout in .net core web app 
Csharp :: unity how to get the side ways velocity of a object 
Csharp :: check if animation is playing unity 
Csharp :: escape double quotes c# 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =