- Home /
Question by
Michael CMS · Oct 22, 2014 at 09:21 AM ·
texturesdynamic loading
How to get at runtime the path of a Texture assigned in the editor ?
To make this as brief as possible, the scenario I'm trying to resolve is as follows :
I put in the editor , on an object a texture named "red" found physically at Resources/House1/red.png.
In the same folder , i also have a texture named "blue", "green" ... you get the point.
There are also other houses , for example Resources/House2.
The houses are 2D so I'm using the GUITexture class .
At runtime I want to make something like this
void Randomize()
{
GUITexture renderingElement = gameObject.GetComponent<GUITexture>();
Texture renderingTexture = renderingElement.texture;
// the following line is pseudocode, GetPathInResources() doesn't exist
string texturePath = renderingTexture.GetPathInResources();
renderingElement.texture = GetRandomTextureFromTexturePath(texturePath);
}
Is there a way to get the path where the texture resides, in order to get other textures from the same folder ?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613165642im_/https://answers.unity.com/themes/thub/images/avi.jpg)