Oussama Ayed
Oussama Ayed

Reputation: 11

Loading a table of texture from unity folder scripting while running on android device

i can load images from external urls and save them into my unity project folder when i run it on my pc (unity player scene) it works perfectly i can load the images located in my project into a table of textures and display it but it's not working while running on android device .it won't load images into texture

DirectoryInfo info = new DirectoryInfo(@"Assets\Photos\");
    int nbImage;

    nbImage = info.GetFiles("*.jpg").Length;
    Debug.Log(nbImage);
    Textures = new Texture2D[nbImage];
    for (int i = 0; i < nbImage; i++)
    {
        string e = Application.streamingAssetsPath + "/" + i + ".jpg";
        byte[] bytes;
        bytes = System.IO.File.ReadAllBytes(e);
        load_s01_texture = new Texture2D(1, 1);
        load_s01_texture.LoadImage(bytes);
        Textures[i] = load_s01_texture as Texture2D;


    }

this how it looks on my pc works fine and this how it looks on my phone not working

Upvotes: 0

Views: 516

Answers (1)

jmcorallo
jmcorallo

Reputation: 344

The directory "Assets\Photos" exists when you are running the project in the Editor, but it doesn't exist on the Android phone.

If you want to load images or other resources at run time, you have to use the resources folder.

Here's a useful example of how to use it

Upvotes: 1

Related Questions