Reputation: 51
The question I'm aksing isn't about the method of reading a string, more about where to place that string, so that if the game is exportet, you can still read it. Because if you assign a path where a txt-Document with that string is found(C:\Users\User\Desktop\string.txt), it wont be there anymore, if you export the game, for exmple onto another pc.
I've tried using the 'Resources.Load' method, but seems not to be working for strings.
string st = Resources.Load<string>("AssetsPath)
So, where or how to save the string?
Upvotes: 0
Views: 463
Reputation: 581
Since you cannot store a string as a resource, I assume you are using a text file as a resource and that you want to load its content. In that case you can use the following code:
TextAsset textAsset = Resources.Load<TextAsset>("AssetsPath");
string st = textAsset.text;
Upvotes: 1
Reputation: 1018
You can use the PlayerPrefs
class to save some data.
Here is an example
PlayerPrefs.SetString("SomeKey", "MyValue");
var myValue = PlayerPrefs.GetString("SomeKey");
More on that here
Upvotes: 1