- Home /
How do I put the texture I get on a sprite?
Hello I have this script and it is getting a .png file and I am wondering how to get it onto a sprite or save it to the asset folder.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class LoadImages : MonoBehaviour {
public string fileslocation = @"C:/images";
public List<Texture2D> images = new List<Texture2D>();
// Use this for initialization
public IEnumerator Start () {
yield return StartCoroutine(
"LoadAll",
Directory.GetFiles(fileslocation, "*.png", SearchOption.AllDirectories)
);
}
// Update is called once per frame
public IEnumerator LoadAll (string[] filePaths) {
foreach (string filePath in filePaths)
{
WWW load = new WWW("file:///" + filePath);
yield return load;
if (!string.IsNullOrEmpty(load.error))
{
Debug.LogWarning(filePath + " error");
} else
{
images.Add(load.texture);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can i lock the mouse cursor in the middle of the screen ? 1 Answer