How to use the file protocol with the WWW class?

Hi guys

I need some help using the file protocol in the WWW class of Unity. I am trying to load a sprite dynamically from the disk. I fetch the name of the file to load from an xml, and try to load it. I do not use Resources.Load as it does not serve my purpose.

This is the code I am currently using :

WWW logoPath = new WWW ("file://F:/Restart/RestartSource/FinalFromServer/ClientLogo.png");

		Texture2D texture = new Texture2D (200, 200);
		while (!logoPath.isDone)
						;

		logoPath.LoadImageIntoTexture (texture);
		Sprite clientSprite = Sprite.Create (texture, new Rect (0.0f, 0.0f, 200.0f, 200.0f), Vector2.zero);

The first issue I am getting is, Unity is unable to open the file. I tried different variations for the protocol specification, including adding a space after the ‘:’, nothing works. Here is the error I get:

You are trying to load data from a www stream which had the following error when downloading.
Couldn’t open file /Restart/RestartSource/FinalFromServer/ClientLogo.png

The file exists and all. Is there something I need to specify for the path?

The next thing I would need help on is resizing the texture I created to the size of the image

I am using Unity 5.0.0fa .Can anyone help me with this? Thanks

Rahul

Try using three forward slashes instead of two.

3 forward slashes:

WWW logoPath = new WWW ("file:///F:/Restart/RestartSource/FinalFromServer/ClientLogo.png");

Edit:

Why do you have a while loop that is not quite a while loop? You have a semi-colon at the end:

while (!logoPath.isDone)
                         ;

Don’t do it like that, use the yield paradigm that Unity’s scripting documentation shows for the WWW class.