I want to create a public function with yield,any program just need enter a URL give to it,will get resources .
What is I to do?
thank all
error message:
You are trying to load data from a www stream which has not completed the download yet.
You need to yield the download or wait until isDone returns true.
using UnityEngine;
using System.Collections;
public class About_Play01_use_field05 : MonoBehaviour
{
public WWW picture;
public Texture2D MyPicture;
public string TextureName01 = "http://localhost:81/img/wow01.jpg";
public bool LoadImages = false;
void Start()
{
MyPicture = StartLoadImage01(TextureName01);
this.renderer.material.mainTexture = MyPicture;
}
void Update () {
}
public Texture2D StartLoadImage01(string TempPicture)
{
Debug.Log("It's Loading Images...... Time : " + Time.time.ToString());
MyCoroutineYield01 MyWWW = new MyCoroutineYield01();
StartCoroutine(MyWWW.MyYield(TextureName02));
Texture2D temp = MyWWW.www.texture;
return temp;
}
}
The MyCoroutineYield01 class
using UnityEngine;
using System.Collections;
public class MyCoroutineYield01
{
public WWW www;
public IEnumerator MyYield(string url)
{
this.www = new WWW(url);
yield return www;
}
}
You need to wait unitl the coroutine is complete before using the www object. Maybe you could pass the texture in to your coroutine class. Example below on how I’d attempt this (this is not tested). It should check the www object every second and set the texture once it’s done while everthing else carries on.
using UnityEngine;
using System.Collections;
public class MyCoroutineYield01
{
public WWW www;
private Texture2D texture;
public MyCoroutineYield01(Texture2D texture)
{
this.texture = texture;
}
public IEnumerator MyYield(string url)
{
this.www = new WWW(url);
while(!www.isDone)
{
yield return new waitforseconds(1);
}
texture = www.texture;
}
}
thank you.
But i don’t want use this www.isDone。So before only use this yield in my code .
Can refer to specific:[You can inspect the isDone property to see if the download has completed or yield the download object to automatically wait until it is (without blocking the rest of the game).