Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

IndexOutOfRangeException: Array index is out of range. Getskin+<DownloadImage>c__Iterator0.MoveNext

Discussion in 'Scripting' started by ErikMartins, Jul 1, 2018.

  1. ErikMartins

    ErikMartins

    Joined:
    Oct 28, 2016
    Posts:
    49
    ERRO:
    IndexOutOfRangeException: Array index is out of range.
    Getskin+<DownloadImage>c__Iterator0.MoveNext

    he is giving error when he is going to download.

    Script:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections;
    4. using System.IO;
    5. using UnityEngine;
    6. using UnityEngine.SceneManagement;
    7. using UnityEngine.UI;
    8.  
    9. public class Getskin : MonoBehaviour
    10. {
    11.  
    12.     public Material materialt;
    13.  
    14.     public RawImage amostra;
    15.  
    16.     public string[] ImageFiles;
    17.  
    18.     public Dropdown picktextura;
    19.  
    20.     private string[] filePaths;
    21.  
    22.     public string path;
    23.  
    24.     //clean
    25.     public void apagar(){
    26.         picktextura.options.Clear ();
    27.     }
    28.     //get files directory
    29.     public void clicouAjuda()
    30.     {
    31.         ImageFiles = getImageFiles();
    32.         char[] delimiterChars = { '/', '\\' };
    33.         foreach (string c in ImageFiles) {
    34.             picktextura.options.Add (new Dropdown.OptionData () { text = System.IO.Path.GetFileName (c) });
    35.         }
    36.     }
    37.     private string[] getImageFiles()
    38.     {
    39.  
    40.         path = "C:\\Skins";
    41.         string[] filePaths = Directory.GetFiles(@path , "*.*" ,SearchOption.AllDirectories);
    42.         foreach (string file in filePaths)
    43.         {
    44.             Debug.Log(file);
    45.         }
    46.         return filePaths;
    47.         {
    48.         }
    49.     }
    50.     //download image
    51.     public void goprala (){
    52.         StartCoroutine(DownloadImage());
    53.     }
    54.     IEnumerator DownloadImage(){
    55.         WWW www = new WWW ("file://" + ImageFiles [picktextura.value]);
    56.         yield return www;
    57.         materialt.mainTexture = www.texture;
    58.         amostra.texture = www.texture;
    59.     }
    60. }
     
  2. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    676
    Line 40 tells me you are using Windows. If you are, maybe you need to change Line 55 to look like this:

    Code (csharp):
    1.         WWW www = new WWW ("file:///" + ImageFiles [picktextura.value]);
     
    ErikMartins likes this.