Hi,
So I currently have a skybox that gets rendered with six still images. I’d like to continue using this method, but with a little different way of getting the images instead of them being in my project. I’d like to have a website that has a picture constantly being updated. There would have to be six sites for this to transmit into a skybox, though for now being perfect images for a skybox doesn’t matter to me, I just want the functionality.
So the code below I used on a plane to pull an image off of a website and apply it to the texture.
// url of image;
var url = "http://ETC";
function Start () {
// Start a download of the given URL
var www : WWW = new WWW (url);
// wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
I’d like to use this same method, but the thing is I don’t know how to apply code to the skybox considering these images are being taken directly from project.
When you switch your inspector into Debug mode you can see the texture parameters in list form. They are:
_FrontTex, _BackTex, _LeftTex, _RightTex, _UpTex, _DownTex
There are also _MainTex
and _Tex
but i guess they aren’t used.
To set them just use [Material.SetTexture][1].
GetComponent.<Skybox>().material.SetTexture("_FrontTex",www.texture);
edit
You can load one texture at a time and load them one by one, or load them all at once. WWW-calls are asynchron so you can start all 6 downloads at once and wait for them to finish.
private static var skyboxTextures : String[] = ["_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex"];
var url = "http://domain/path/to/skybox/folder/";
function LoadSkybox(skyboxName : String)
{
var www : WWW[] = new WWW[6];
for (var i = 0;i < 6; i++)
{
www _= new WWW(url + skyboxName + skyboxTextures *+ ".png");*_
}
var mat = GetComponent.().material;
for (i = 0;i < 6; i++)
{
yield www*; // wait for all images to finish*
mat.SetTexture(skyboxTextures_,www*.texture);
}
}*_
function Start()
{
LoadSkybox(“desert”);
* // Images should be named:*
* // “desert_FrontTex.png”
// “desert_BackTex.png”
_ // …
}
[1]: http://unity3d.com/support/documentation/ScriptReference/Material.SetTexture.html*_
dont forget to clamp the textures, the famous white lines would appear on your skybox