- Home /
Downloading an image displaying it won't work on Android
Hi, I have a script that downloads my image to a texture and converts it to a sprite to display on a Unity UI image. It works well in the editor and all seems to be fine, It downloads and displays the image correctly but as the title says when I build to android the Image never displays. Could somebody take a look at my script and see if there's any reason as to why it won't work?
Just to clarify the build does have "full Network Access" I have also tried adding the "http" after as I read that it gets dropped. It works neither way.
Here's the script.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class AccountGetter : MonoBehaviour {
public string url = "www.gdurl.com/jMu9";
public Text fail;
IEnumerator Start() {
//Create a new texture2D
Texture2D tex;
tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
//Grab the image from the web
WWW www = new WWW("http://" + url);
//Wait for the download
yield return www;
//Load the image to the texture 2D
www.LoadImageIntoTexture(tex);
//Simple check to see if there's indeed a texture available
if (www != null) {
//Construct a new Sprite
Sprite sprite = new Sprite ();
//Create a new sprite using the Texture2D from the url.
sprite = Sprite.Create (tex, new Rect (0, 0, 977, 1425), Vector2.zero);
//Assign the sprite to the Image Component
GetComponent<UnityEngine.UI.Image> ().sprite = sprite;
} else {
fail.GetComponent<Text> ().enabled = true;
fail.text = "FAILED TO DOWNLOAD";
}
}
}
Thanks for looking.
Your answer
Follow this Question
Related Questions
Make accented letters show in text field on Android? 2 Answers
How to make work properly a game on different android phones? 1 Answer
Android : How to manage game display with on-screen front cameras ? 1 Answer
www.Texture V.S. LoadImageIntoTexture() 2 Answers
How to get the color depth (bits per pixel) property of display? 0 Answers