Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WWW - Url change in coroutine is not working?

Discussion in 'Scripting' started by Bongmo, May 22, 2016.

Thread Status:
Not open for further replies.
  1. Bongmo

    Bongmo

    Joined:
    Jan 18, 2014
    Posts:
    155
    I use this WWW script: http://docs.unity3d.com/ScriptReference/WWW.html

    It's working. But when I change the code to this:

    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.    
    4.     public class ExampleClass : MonoBehaviour {
    5.         public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
    6.                
    7.     void Start () {
    8.  
    9.         StartCoroutine (Co ());
    10.        
    11.     }
    12.  
    13.         IEnumerator Co() {
    14.  
    15.             // *** THIS IS THE NEW LINE ***
    16.             url = "http://NEW URL";
    17.                
    18.             WWW www = new WWW(url);
    19.             yield return www;
    20.                
    21.             Renderer renderer = GetComponent<Renderer>();
    22.             renderer.material.mainTexture = www.texture;
    23.         }
    24.     }

    It's not working. Why?

    I printed the new URL in the console and tested it. The new url works.

    So, the new url change in the coroutine is not working.
     
  2. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Your example works fine for me.
    What do you mean by "not working". What happens?
    Did you maybe put this code in a script named something other than "ExampleClass" ?
     
Thread Status:
Not open for further replies.