问题
I'm trying to load a Texture
from the Resources
folder but it keeps on returning null
.
t = (Texture)Resources.Load("Circle") as Texture;
The circle texture has an extension of .tga
.
回答1:
You must put Circle.tga in Assets/Resources folder. Plus if you have subfolder, for example Resources/Textures/Circle.tga then do like this:
Texture t = Resources.Load("Textures/Circle") as Texture;
回答2:
The extension of the file isn't necessary. So this is correct:
t = (Texture)Resources.Load("Circle") as Texture;
This is not:
t = (Texture)Resources.Load("Circle.npg") as Texture;
回答3:
Single Texture File
Texture File should be added into Resources folder After that use below lines of code for load texture
var Texture_1 : Texture2D;
Texture_1 = Resources.Load("TextureName");
For Folder
Folder should be in kept into Resources folder After that use below lines of code for load folder of textures
var textures : Object[];
textures = Resources.LoadAll("FolderName");
来源:https://stackoverflow.com/questions/16092200/calling-resources-load-on-a-texture-is-not-working