Home > Mobile >  How to correctly read 'string' Unity?
How to correctly read 'string' Unity?

Time:06-03

The question I'm aksing isn't about the method of reading a string, more abput 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, 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 to save the string?

CodePudding user response:

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

CodePudding user response:

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;
  • Related