- Home /
C# Resources.Load() problem
I try to load image by script.
But I don't load image.
Is there any way to load a texture from a string reference?
code
public class LearningScript : MonoBehaviour
{
private Texture testTexure; void Start() {
Object temp = Resources.Load("iPhone Standard Assets/Textures/sky_02");
if ( temp == null )
Debug.Log("Load Object Fail");
testTexure = Resources.Load("iPhone Standard Assets/Textures/sky_02" ) as Texture;
if ( testTexure == null )
Debug.Log("Load Texture Fail");
}
}
resource
result
@Exotic, in addition to checkmarking the best answer (which you did), it's helpful to upvote good answers, not only here, but any others that you find useful or informative.
Cyclops: and upvoting requires 15 rep, which Exotic doesn't have yet.
I'm in a similar situation, I'd like to change the Resources.Load("A string") as texture; with the replace function, allowing the texture to changed with logic at runtime.
YES: you could just list all your textures in an array and select that way, but rather make it more efficient. -esp as I have 100 odd textures to update on runtime.
so far the closest i've got :
Void Update { {
Texture Startingframe = Resources.Load("frame_000") as Texture;
frameselectED = frameselect.Replace("000", "092");
renderer.material.mainTexture = Startingframe; } }
the frameselectED can then obv be changed with some arithmetic.
Answer by TrolleFar · Apr 09, 2010 at 07:05 AM
You can only load textures, models etc, by using Resources.Load if they are placed under a folder named "Resources" (see the scripting reference for more info). So if you move your sky_02 texture to a folder named "Resources" and change the "iPhone Standard Assets/Textures/sky_02" string to simply "sky_02" it should work.
and note you can keep your resources organized in sub-folders and pass the relative path to Resources.Load, for example move sky_02 to Resources/Textures and use Resources.Load("Textures/sky_02").
thanks for the answer. It wasnt a very obvious solution. I wouldnt discover that if i didint read this thread..