Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

So many lightmaps

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

  1. waizui

    waizui

    Joined:
    Dec 12, 2018
    Posts:
    3
    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:
    5,257
    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:
    3
    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:
    5,257
  5. waizui

    waizui

    Joined:
    Dec 12, 2018
    Posts:
    3
    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;
    }
    }

    }