So… I’ve always thought it would be a cool idea for a game to allow the player to import their own custom textures and use them to say paint a car. What namespaces / methods would be used to pull these custom textures into the resources folder via code so I can make this happen?
Thanks for your time!
You’d use standard C# file I/O to read the file, and then Texture2D.LoadImage to turn that data into a texture.
Cool, but what kind of reader would that be? (System.IO.“???”) … Assuming I’m understanding this correctly.
(needs to set a byte array it looks like)
Sorry I haven’t been coding for long 
Yes, you need to use the standard IO to load a byte array. The easiest way is using File.ReadAllBytes(filePath). Here’s some code to get you started:
byte[] data = File.ReadAllBytes("test.png");
Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
texture.LoadImage(data);
Awesome thanks so much!!!
and while I’m here is there a conversion to turn Texture2D to Sprite? (For Icons)
thanks again.
Yeah, you can use Sprite.Create.
Thank you all for your help!
I’m super exited to implement these new lessons, you guys rock! 
1 Like