How to load resources?
I've made a "Resources" folder in Assets and imported there a tmp.txt withone string. Then I've put the next code to MainCamera:
public GameObject text1; // assigned a text in editor for this
void Start () {
Text txt1;
txt1 = text1.GetComponent();
TextAsset textDoc = Resources.Load ("/Resources/tmp.txt") as TextAsset;
if (textDoc == null) txt1.text = "null";
else txt1.text = textDoc.text;
...
}
So, I tried to put different arguments instead of "/Resources/tmp.txt", like "tmp.txt", "\Resources\tmp.txt", "" but I always get "null", not the string that there is in a text file. So, actually, how can I access files with resources mechanism in Unity?
Answer by hexagonius · Nov 20, 2016 at 02:15 PM
According to the docs about TextAsset, you're pretty close:
https://docs.unity3d.com/Manual/class-TextAsset.html
TextAsset textDoc = Resources.Load ("tmp") as TextAsset;
Your answer
Follow this Question
Related Questions
Resource.Load always returning null when trying to load an image 1 Answer
Is there a way to reveal resources in the built folder structure? 0 Answers
How to do something similar to AssetDatabase.Refresh during build? 0 Answers
Files put inside a Resources folder still don't end up in the build 1 Answer
What use instead of Resources folder? 3 Answers