I am trying to dispose a WWW object if a timeout occurs. I am using following code:
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");
}
But I am getting exception:
NullReferenceException: WWW class has already been disposed. TestScript+c__Iterator2.MoveNext ()
I am not sure what I am doing wrong here.
Can anybody help me in this?
 
     
     
     
    