webplayer www sendmessage to loadExternalImage with parameter (url)

Hi there,

I would like to use “loadExternalImage” from web player and send him the url where to find the image.

here is the javascript in the webplayer:

unityObject.getObjectById("unityPlayer").SendMessage("housse_avant", "Start", "http://www.myUrl.net/housse.jpg");

here’s the javascript in unity :

// Load image

function Start (url: String) {
    // Create a texture in DXT1 format
    renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
    //while(true) {
        // Start a download of the given URL
        var www = new WWW(url);

        // wait until the download is done
        yield www;

        // assign the downloaded image to the main texture of the object

Why I want to do this is because the user must be able to upload his texture which I give a random name that will be sent to unityPlayer.

Any idea?

You cant’ use

unityObject.getObjectById("unityPlayer").SendMessage("housse_avant", "Start", "http://www.myUrl.net/housse.jpg");

because method sign is:

void SendMessage(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver);

You may create a object (a class/struct) that contains both parameter and pass that, or you can use an object array.


unityObject.getObjectById("unityPlayer").SendMessage("Start", objectArray, SendMessageOptions.RequireReceiver);

Good Luck