我正在尝试Texture
从Resources
文件夹中加载一个,但它一直在返回null
。
t = (Texture)Resources.Load("Circle") as Texture;
圆形纹理的扩展名为.tga
.
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");
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");
文件的扩展名不是必需的。所以这是正确的:
t = (Texture)Resources.Load("Circle") as Texture;
这不是:
t = (Texture)Resources.Load("Circle.npg") as Texture;
您必须将 Circle.tga 放在 Assets/Resources 文件夹中。另外,如果您有子文件夹,例如 Resources/Textures/Circle.tga 然后这样做:
Texture t = Resources.Load("Textures/Circle") as Texture;
@Massimiliano Uguccioni 谢谢...解决了我的问题。
使用 Resources.load 的步骤: