- Home /
How does a TextAsset work?
I'm somewhat of a noob to Unity and scripting in it, and I am trying to be able to read and modify a text file. I have been pointed to the link below by this helpful Unity Answers community, and I am hoping that you could do the same for this question of mine. The link to TextAssets is here.
I am basically wondering what I am supposed to do with that from a start. I am not trying to get you to "write my scripts" but I would appreciate an example or a link to help about this.
I just want a quick script that will read the text file into a variable, and an other one that will take a variable and edit the file.
Thank you!
TextAsset ta;
string str;
private void Awake()
{
str = ta.text;
}
The TextAsset class does not possess the functionality of letting you write onto a text file.
So that's just to read it? Where does it say the name and location of the text file? Thank you for your reply!
For editing a text file, should I use that "system.IO" thing or whatever? I will ask a separate question for that. Or just push the button to answer the question right now and give me an example of that if you know it, and you'll get a best answer!
Dreamblur's comment is certain the Answer. Also consider PlayerPrefs, depending on why you're wanting to write a text file.
Answer by Dreamora · Jul 10, 2011 at 11:03 PM
TextAssets only exist for text files present in the build. As with any other files included in the build, they cease to exist as distinct files, which removes aspects like "path" (either its hooked up on a monobehaviour or must be in resources to be present in the build at all) or "file" which would be required if you want to write to it at runtime.
For runtime write to the file you would use System.IO in detail System.IO.File
Depending on what data you need to write, PlayerPrefs can be an option but there are relevant things to keep in mind on that end that might make it unfavorable (they are per version based so if you change the version in the player settings, the old prefs will no longer be used)
Your answer
Follow this Question
Related Questions
Basic Question about TextAssets 0 Answers
Loading TextAsset returns null 1 Answer
parsing csv file 2 Answers
2D array problem in C# 2 Answers