Hi,
I’m new. I’ve searched the forums and Google, read a lot, but nothing that helps me.
All this is at runtime. I can’t do this in the IDE ![]()
I want to dynamically load in X images, and generate X Cubes.
I then only want to texture one side of the cube. The other sides I want to apply different textures to.
I’m guessing I need to use cubemaps, right?
For testing, I’m trying a basic example. At first I’ve got a 2x2x2 cube in the IDE. I’ve applied a 2x2 texture (called ‘checker’) to it.
I’m now trying to generate a cubemap from the 2x2 texture using this code:
var tex:Texture2D = Resources.Load("checker");
gameObject.renderer.material.mainTexture = tex;
var cubemap:Cubemap = new Cubemap(2, TextureFormat.ARGB32, false);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.NegativeX);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.NegativeY);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.NegativeZ);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.PositiveX);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.PositiveY);
cubemap.SetPixels(tex.GetPixels(),CubemapFace.PositiveZ);
cubemap.Apply();
gameObject.renderer.material.mainTexture = cubemap;
I get this error:
Error assigning cubemap texture to 2D texture property '_MainTex': Dimensions must match
UnityEngine.Material:SetTexture(String, Texture)
UnityEngine.Material:SetTexture(String, Texture)
UnityEngine.Material:set_mainTexture(Texture)
CubeMapTest:Start() (at Assets\CubeMapTest.js:26)
[..\..\External\shaderlab\Library\properties.cpp line 260]
Can anyone see what I’m doing wrong? Or can someone suggest a better way of doing this?
Thanks! ![]()