2

我正在尝试TextureResources文件夹中加载一个,但它一直在返回null

t = (Texture)Resources.Load("Circle") as Texture;

圆形纹理的扩展名为.tga.

4

4 回答 4

2

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");
于 2013-09-02T11:17:06.997 回答
2

文件的扩展名不是必需的。所以这是正确的:

t = (Texture)Resources.Load("Circle") as Texture;

这不是:

t = (Texture)Resources.Load("Circle.npg") as Texture;
于 2013-08-19T15:03:50.550 回答
2

您必须将 Circle.tga 放在 Assets/Resources 文件夹中。另外,如果您有子文件夹,例如 Resources/Textures/Circle.tga 然后这样做:

Texture t = Resources.Load("Textures/Circle") as Texture;
于 2013-04-23T13:45:01.523 回答
1

@Massimiliano Uguccioni 谢谢...解决了我的问题。

使用 Resources.load 的步骤:

  1. 确保它在资源文件夹中
  2. 参考没有资源的完整相对路径:例如:纹理/纹理1,其中纹理是资源中的文件夹
  3. 像 Massimiliano Uguccioni 说的不包括文件扩展名
于 2021-09-30T10:17:29.433 回答