How to set a skybox from an image url?

Hello, I would like to set the current scene’s skybox according to an image url, which is a cubemap.

This is the code I have so far, but the result just a blank gray skymap.
Any help would be much appreciated!

using UnityEngine;
using System.Collections;

public class CreateCubemap : MonoBehaviour {

    public Cubemap cube;
    public string url = "http://i.imgur.com/mkdBN4b.jpg";
    private Color[] imageColors;
    private Texture2D loadedImage;
    public WWW www;
    private int size = 1024;
    public Material oldmat;
    public Material mat;
     // Use this for initialization
    void Start () {
        loadedImage = new Texture2D(size * 12, size, TextureFormat.RGB24, false);
        StartCoroutine(loadImage());


    }

    IEnumerator loadImage()
    {
        mat = new Material(oldmat);
        www = new WWW(url);
        yield return www;
        www.LoadImageIntoTexture(loadedImage);

        cube = new Cubemap(size, TextureFormat.RGB24, false);
        imageColors = loadedImage.GetPixels(0, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveX);
        imageColors = loadedImage.GetPixels(size, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeX);
        imageColors = loadedImage.GetPixels(size * 2, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveY);
        imageColors = loadedImage.GetPixels(size * 3, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeY);
        imageColors = loadedImage.GetPixels(size * 4, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveZ);
        imageColors = loadedImage.GetPixels(size * 5, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeZ);
        mat.SetTexture("_Cube", cube);
        RenderSettings.skybox = mat;
    }
   
    // Update is called once per frame
    void Update () {
   
    }
}

Hi,

Missing cube.Apply(); after the last SetPixels line

Thank you for the response!

I added cube.Apply(); after the last SetPixels line like you suggested, but it still results in a gray skybox.
Anything else I am missing?

If you use Skybox/Cubemap shader, the texture name is “_Tex”, not “_Cube”
You can see that by selecting the shader
2733781--194340--upload_2016-8-2_15-45-2.png

I had modified it a bit:

using UnityEngine;
using System.Collections;

public class LoadSkyBoxWWW : MonoBehaviour
{
    public Cubemap cube;
    public string url = "http://i.imgur.com/mkdBN4b.jpg";
    private Color[] imageColors;
    private Texture2D loadedImage;
    public WWW www;
    private int size = 1024;
    public Material skyboxMat;

    void Start()
    {
        loadedImage = new Texture2D(size * 12, size, TextureFormat.RGB24, false);
        StartCoroutine(loadImage());
    }

    IEnumerator loadImage()
    {
        www = new WWW(url);
        yield return www;
        www.LoadImageIntoTexture(loadedImage);

        cube = new Cubemap(size, TextureFormat.RGB24, false);
        imageColors = loadedImage.GetPixels(0, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveX);
        imageColors = loadedImage.GetPixels(size, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeX);
        imageColors = loadedImage.GetPixels(size * 2, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveY);
        imageColors = loadedImage.GetPixels(size * 3, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeY);
        imageColors = loadedImage.GetPixels(size * 4, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.PositiveZ);
        imageColors = loadedImage.GetPixels(size * 5, 0, size, size);
        cube.SetPixels(imageColors, CubemapFace.NegativeZ);
        cube.Apply();

        skyboxMat.SetTexture("_Tex", cube);
        RenderSettings.skybox = skyboxMat;
    }
}

This works perfectly!
Thank you so much :smile:

exlente consejo