- Home /
 
Choose a texture in-game
Hello everyone,
I am currently making a game about boxes. And I like to have a system that the user can choose his own texture from his computer. Is this possible?
Answer by CHPedersen · Jun 30, 2014 at 11:11 AM
Sure. The problem here is that you can't use Resources.Load like one normally would, because if the user chooses the file on his own machine, then there's no way for you to include it in the distributed Resources folder. But, you can load a texture from an arbitrary location through the WWW class.
It's actually intended for online URLs, but you can just specify the URL as a path to a local file using the file-protocol. This works on my machine:
     WWW www = new WWW(@"file:///[Path on disc here]");
     Texture2D theTexture = www.texture;
 
               I'm supplying three slashes in the path (///) due to the comments in the documentation for Windows here. It's probably only two slashes (//) on a Mac, but I haven't tested that.
Your answer