Hi, Ive got major issues. The below code works in the editor and web player.
IEnumerator Start()
{
String imageAssetPath = "file://" + Application.dataPath + "/img.jpg";
www = new WWW(imageAssetPath);
yield return www;
renderer.material.mainTexture = www.texture;
}
However, the following code works in the editor but not the player:
IEnumerator Start()
{
String imageAssetPath = "file://" + Application.dataPath + "/img.jpg";
www = new WWW(imageAssetPath);
yield return www;
texture = new Texture2D(www.texture.width, www.texture.height);
renderer.material.mainTexture = texture;
colors = www.texture.GetPixels(0, 0, www.texture.width, www.texture.height);
texture.SetPixels(colors, 0);
texture.Apply(false);
}
Why wont this work in the web player? Its not making any sense.
Obviously the two version are similar. I’m actually looking to expand on this (if i can get it going).
Thanks
The webplayer can not access file:// or the local system at all to be more specific.
you can only request data from webservers out there (http://)
Even if i change the asset path to:
IEnumerator Start()
{
String imageAssetPath = "http://download.unity3d.com/images/front/unite10_front_keynotevideo.jpg";
www = new WWW(imageAssetPath);
yield return www;
texture = new Texture2D(www.texture.width, www.texture.height);
renderer.material.mainTexture = texture;
colors = www.texture.GetPixels(0, 0, www.texture.width, www.texture.height);
texture.SetPixels(colors, 0);
texture.Apply(false);
}
The same issue occurs. Works in the editor but not the web player.
Please note that
String imageAssetPath = "http://download.unity3d.com/images/front/unite10_front_keynotevideo.jpg";
www = new WWW(imageAssetPath);
yield return www;
renderer.material.mainTexture = www.texture;
works in both.
Any help would be highly appreciated
As mentioned on the other thread (I think it was yours as the code sample resembles it), please check out the manual on security sandbox in U3 webplayer, what you are seeing here is the consequence of your attempts to break security basics.
GetPixels is not allowed on textures you loaded from outside for security reason unless have a crossdomain xml present there for example.
You can still use it through www.texturefor such textures from a not crossdomained place but you can’t get the images content anymore
If i use url:
http://centers.law.nyu.edu/jeanmonnet/images/TL_map-world.jpg
i get the error
SecurityException: No read access to the texture data
which is generated on the GetPixels call
But when i use the url
http://unity3d.com/images/front/unite10_front_keynotevideo.jpg
Which has the cross domain poliy at:
http://unity3d.com/crossdomain.xml
The error goes away but it doesn’t work in the web player
I have also got the project setting : Emulate Web Security, so i don’t think its a security issue.
Thanks for your help
Below is my code and i m not able to download image :
if(GUI.Button(new Rect (200, 300, 100, 30),“DOWNLOAD”))
{
url = “http://images.earthcam.com/ec_metros/ourcams/fridays.jpg”;
WWW www = new WWW(url);
//Debug.Log(“Download Clicked”);
StartCoroutine(download(www));
}
public IEnumerator download(WWW www)
{
yield return www;
Debug.Log("Texture Name : " + www.texture.name);
}
m not able to download image from this http link…
and and not get any error also.
So help me to solve this issue…
Thanks in advance