I need to set the Lightmap texture by the code.
I’ve tried this:
if(is_lightmapped){
Texture2D lmTex=Resources.Load("lightmaps", typeof(Texture2D)) as Texture2D;
LightmapData[] lightmaparray = new LightmapData[1];// LightmapSettings.lightmaps;
LightmapData mapdata = new LightmapData();
mapdata.lightmapFar = lmTex;
mapdata.lightmapNear = lmTex;
lightmaparray[0] = mapdata;
LightmapSettings.lightmaps = lightmaparray;
}
but it doesn’t work.
Note that my lightmaps texture is in a Resources folder.
I’ve done something similar with the texture atlas:
Material theNewMaterial = Resources.Load("Materials/"+texture_atlas_name, typeof(Material)) as Material;
Material[] mats;
mats = meshRenderer.materials;
mats[0] = theNewMaterial;
meshRenderer.materials = mats;
and it works but i need to do the same with the lightmap texture.