Search Unity

So many lightmaps

Discussion in 'General Graphics' started by waizui, Jan 11, 2019.

  1. waizui

    waizui

    Joined:
    Dec 12, 2018
    Posts:
    13
    Hi guys , i'm working on some problems:
    1.i want use this code below to switch lightmap in my scene

    public Texture2D lightmap1;
    LightmapData data=new LightmapData();
    data.lightmapColor=lightmap1;
    LightmapSettings.Lightmaps=new LightmapData[1]{data};

    2.but there is a problem. there are three lightmaps in my lightmap folder,which should i use in the code? UNADJUSTEDNONRAW_thumb_569.jpg
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    If you want to switch lightmaps (for different lighting conditions or something I assume?), you need to change all three.
     
  3. waizui

    waizui

    Joined:
    Dec 12, 2018
    Posts:
    13
    thanks for reply ,but I'm still confused , should I create a array contains all three lightmaps then give it to lighmapsettings.lightmaps? And what about the index of lightmaps?
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
  5. waizui

    waizui

    Joined:
    Dec 12, 2018
    Posts:
    13
    Update:
    Fixed!

    using UnityEngine;

    public class LightMapSwitch : MonoBehaviour
    {

    public Texture2D[] dayMap;
    public Texture2D[] NightMap;
    private void OnGUI()
    {
    if (GUILayout.Button("<size=50>day</size>"))
    {
    foreach(Texture2D tex in dayMap)
    {
    Debug.Log(tex.ToString());
    }
    LightmapData[] datas = new LightmapData[3];
    for (int i= 0; i < datas.Length; i++)
    {
    LightmapData data= new LightmapData();
    data.lightmapColor = dayMap[i];
    datas[i] = data;

    }
    LightmapSettings.lightmaps = datas;
    }
    if (GUILayout.Button("<size=50>Night</size>"))
    {
    LightmapData[] datas = new LightmapData[3];
    for (int i = 0; i < datas.Length; i++)
    {
    LightmapData data = new LightmapData();
    data.lightmapColor = NightMap[i];
    datas[i] = data;
    }
    LightmapSettings.lightmaps =datas;
    }
    }

    }