I’m not suggesting the script below is a good idea, but I was just trying t find a way to get a texture to update now and then. With this script attached to a plane in Unity iPhone, it works fine. But build it to the phone and it just works for the first picture load. After that you have to hold both the home button and the off button for several seconds to regain control of the phone.
Here’s the script:
var url = “http://images.earthcam.com/ec_metros/ourcams/fridays.jpg”;
var i = 0;
var www : WWW;
function Start () {
www = new WWW (url);
yield www;
renderer.material.mainTexture = www.texture;
}
function FixedUpdate(){
transform.Rotate(Vector3.right * Time.deltaTime5);
transform.Rotate(Vector3.up * Time.deltaTime3, Space.World);
i++;
if(i>80){
renderer.material.mainTexture = www.texture;
}
if(i>90){
www = new WWW (url);
i = 0;
}
}
Yes, the Unity editor is very forgiving and tolerant of exceptions, giving you a notification and an opportunity to fix them before release. But once it’s compiled to ARM instructions and put on the iPhone, you’re doing acrobatics without a safety net.
You should really take everything after the transform.Rotate lines out of FixedUpdate…counting to 80 doesn’t tell you whether the download is complete or not, so you could well be trying to assign a null texture. A better way would be:
var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
function Start () {
while (true) {
var www = new WWW (url);
yield www;
renderer.material.mainTexture = [url]www.texture;[/url]
yield WaitForSeconds(5);
}
}
function FixedUpdate(){
transform.Rotate(Vector3.right * Time.deltaTime*5);
transform.Rotate(Vector3.up * Time.deltaTime*3, Space.World);
}