Calling Resources.Load on a texture is not working

本小妞迷上赌 提交于 2020-01-13 20:43:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!