- Home /
Duplicate Question
How to load a textAsset from a txt in the resources folder
Hi! trying to load a txt into a textasset with the resource load (added my image getter just for reference and reading). For the images it works fine but the txt part... its only 1 .txt in a folder. Tried like it is now and also with "/text/"+print2+".txt" ... (print2 is the name of the file.
any clues? it just gives error, having a direct path to the file or only having to the folder...
Thxs :)
(sry for the ugliness of the posted code, still not sure how to make it pretty :P)
GameObject print1 = GameObject.Find("variables"); string print2 = print1.GetComponent<SaveVariables>().name; print ("print: "+ print2);
foreach(Texture2D g in Resources.LoadAll("contos/"+ print2 +"/images", typeof(Texture2D))){ Debug.Log("aaaa: " + g); TextList.Add(g); }
TextAsset pathTxt = (TextAsset)Resources.Load("contos/"+ print2+"/text/", typeof(TextAsset)); if(pathTxt != null){ Debug.Log ("ok!"); }else{ Debug.Log("error"); }
Did you succeed to load a textAsset from a text file in the resouces folder, which is under the created folder when you built?
Answer by Slobdell · Apr 02, 2014 at 07:56 PM
I think it's the path part that's screwy, you need to specify the path starting at resources without the extension. So if your file is called print2 I think you want
TextAsset pathTxt = (TextAsset)Resources.Load("contos/"+ print2+"/text/print2", typeof(TextAsset));
Follow this Question
Related Questions
Resources.Load wont read text file 6 Answers
How to properly load textures? 2 Answers
Altering prefab at runtime. Works in editor, not in build. 2 Answers
Resources load on editor 0 Answers