Here's what I'm trying to do:
I use system.IO to generate a list of files in an image folder. I then take the location of each file and replace some characters to create a well formed url for Unity's WWW class. I then instantiate a simple plane prefab for each file found and using WWW I grab the image file from the folder and assign it as a texture to the instanced plane prefab. What I want is for each prefab plane to have the appropriate image from the WWW request.
The following code almost accomplishes this but what happens is this:
It creates the correct number of prefabs - one for each file found in the folder. But instead of assigning a unique image to each prefab, it assigns the last file found in the parsed folder (say image004 of 4) to each prefab, except for the first prefab, which ends up with a missing material and no image.
Here is my code as it stands (messy but somewhat functional), any help will garner much respect and happiness on my part:
import System.IO;
var ImagesLoaded : boolean = false;
private var path : String = "C:/Users/home/Documents/_MarbleMoto/Images/";
var newImageTile = Resources.Load("ImageTile");
var arr = new Array ();
function Start() {
CreateImageTiles();
}
function CreateImageTiles() {
if(!ImagesLoaded) {
var info = new DirectoryInfo(path);
var fileInfo = info.GetFiles();
for (file in fileInfo)
{
url = file.ToString();
var myNewURL = "file://" + url.Replace("\\", "/");
arr.Push (myNewURL);
ImagesLoaded = true;
}
}
if(ImagesLoaded) {
for (var i=0;i<arr.length;i++)
{
print(arr*);*
_var www = new WWW(arr*);*_
_*yield www;*_
<em>_Instantiate(newImageTile, Vector3(0, i * 3.0, 0), transform.rotation);_</em>
_*//newImageTile.renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);*_
_*//www.LoadImageIntoTexture(newImageTile.renderer.material.mainTexture);*_
_*newImageTile.renderer.material.mainTexture = www.texture;*_
_*}*_
_*}*_
_*}*_
_*```*_