如果发生超时,我正在尝试处理 WWW 对象。我正在使用以下代码:
WWW localWWW;
void Start ()
{
stattTime = Time.time;
nextChange = Time.time + rotationSpeed;
StartCoroutine ("DownloadFile");
}
bool isStopped = false;
bool isDownloadStarted = false;
// Update is called once per frame
void Update ()
{ //2.0f as to simulate timeout
if (Time.time > stattTime + 2.0f && !isStopped) {
isStopped = true;
isDownloadStarted = false;
Debug.Log ("Downloading stopped");
StopCoroutine ("DownloadFile");
localWWW.Dispose ();
}
if (isDownloadStarted) {
}
if (Time.time > nextChange && isDownloadStarted) {
Debug.Log ("Current Progress: " + localWWW.progress);
nextChange = Time.time + rotationSpeed;
}
}
IEnumerator DownloadFile ()
{
isDownloadStarted = true;
GetWWW ();
Debug.Log ("Download started");
yield return (localWWW==null?null:localWWW);
Debug.Log ("Downlaod complete");
if (localWWW != null) {
if (string.IsNullOrEmpty (localWWW.error)) {
Debug.Log (localWWW.data);
}
}
}
public void GetWWW ()
{
localWWW = new WWW (@"http://www.sample.com");
}
但我得到了例外:
NullReferenceException:WWW 类已被释放。TestScript+c__Iterator2.MoveNext()
我不确定我在这里做错了什么。
有人可以帮我吗?