Hello,
I’m able to download the image properly, but when trying to obtain the progress while it loads I’m running into an Object reference issue, and I can’t quite figure it out. Any ideas? ( Object reference not set to an instance of an object )
It happens on this line: var progress : float = wwwimg.progress;
function Update () {
if (!imgStarted) // If the image hasn't started downloading...
{
var wwwimg : WWW = new WWW (urlimg); // Download the image from urlimg
imgStarted = true; // Set to true so it doesn't keep looping
}
if (!imgLoaded) // if the image isn't loaded yet
{
var progress : float = wwwimg.progress; // set a variable to hold the progress
if (wwwimg.progress == 1) // if the progress = 1 (done)
{
print ("it's done!"); // Print that it's done in consol
var imgLoaded = true; // Toggle imgLoaded to true
}
else
{
print( "Download Progress: " + 100*wwwimg.progress + "% ..." ); // If not done, print progress to consol
}
if (imgLoaded == true) // If image is done
{
renderer.material.mainTexture = wwwimg.texture; // Add the image as texture to this.material
}
}
}
// Below is a similar, simpler method of doing the same thing, same error, however.
function Update () {
if (!imgStarted) // If the image hasn't started downloading...
{
var wwwimg : WWW = new WWW (urlimg); // Download the image from urlimg
imgStarted = true; // Set to true so it doesn't keep looping
}
if (wwwimg.progress != 1)
{
print( "Download Progress: " + 100*wwwimg.progress + "% ..." );
}
else
{
if (imgLoaded == false) // If image is done
{
renderer.material.mainTexture = wwwimg.texture; // Add the image as texture to this.material
imgLoaded = true;
}
}
}