- Home /
Rendering Image Sprites Programatically
I know that using the Resources.LoadAssetAtPath()
renders and set the images of the sprite programatically as long as it used only for testing at Game view only. When I publish and export into APK file for Android, the images appeared empty instead. Since, I believe that using Resources.Load()
function is useful to render images or sprites programatically via C-sharp or Javascript. I'm not sure if I did right. Here's what I did:
switch(index) {
case 0: filename = "Assets/Resources/Images/Fruits/kiwi.png"; break;
case 1: filename = "Assets/Resources/Images/Fruits/orange.png"; break;
case 2: filename = "Assets/Resources/Images/Fruits/lemon.png"; break;
case 3: filename = "Assets/Resources/Images/Fruits/strawberry.png"; break;
case 4: filename = "Assets/Resources/Images/Fruits/watermelon.png"; break;
}
Sprite sprite = Resources.Load (filename, typeof(Sprite)) as Sprite;
renderer.sprite = sprite;
I think you can remove "Assets/Resources/" from all those paths. Not sure if that'll fix your problem, but worth a shot.
It's not working, @nesis. Therefore, you need a complete file directory even if exported in AP$$anonymous$$ during buld and run session. :-(
I'm sure that you should remove the Assets/Resources since the assets folder DO NOT EXIST in the game build. I'm sure @nesis is 100% percent correct
and please remove the .png at the end of the line. since a Sprite asset isn't necessary a png...it could be a jpg, PSD or any other image formate supported by unity and then see what happens.