#pragma strict
import System.IO;
public static var FondoEscena : Texture2D; // La hago estática
public var url: String = "http://imagen.com/images001.png";
public var url2: String = "file://"+ Application.persistentDataPath + "/FondoEscena.png";
function Start () { var w = new WWW(url2);
yield w;
renderer.material.mainTexture = w.texture;
Debug.Log(w.error);
if (w.error != null) {
print("No hay la imagen");
BajarFotodeInter(); } else {
FondoEscena = w.texture;
print("Imagen recuperada del celular"); }
}
function BajarFotodeInter () {
var www: WWW = new WWW(url);
yield www; // asignar textura var renderer: Renderer = GetComponent.<Renderer>();
FondoEscena = www.texture; var bytes = FondoEscena.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/FondoEscena.png", bytes); renderer.material.mainTexture = www.texture;
}