I had codes work well in editor like the following:
texture = Resources.Load(fileName, typeof(Texture2D));
object.render.material.mainTexture = (Texture2D)texture;
by placing a jpg file inside
ProjectFolder\Assets\Resources
But after I build the project for a standalone program, the texture doesnt show. I have tried to put the jpg file in the following paths:
StandaloneFolder\ProjectName_Data\Resources
StandaloneFolder\Assets\Resources
Both doesn’t work.
Thanks for help.
I would guess your filename isn’t correct.
When you build your project, your assets in the Resources folder are automatically in the standalone build. You don’t need to copy the assets manually or something like that.
Your filename doesn’t need the extension, maybe that’s your problem.
Mizuho
June 29, 2012, 8:54am
3
I know for sure that loading a JPG in at runtime will work, because I’m loading ALL my pictures like that.
So my filesystem looks like this:
ProjectFolder
|~Resources
|~Fonts
|~Images
|~Gameplay
|~Puzzles
|-drow-arkheneld.png
`-drow-melarn.jpg
|~Prefabs
|~Shaders
|~Sounds
|~Textures
And I load, for example drow-arkheneld.png
, like this:
object.renderer.material.mainTexture = Resources.Load("Images/Puzzles/drow-arkheneld") as Texture;
I can guarantee this works because I took it right out of my own code (save for the object
part).