Swaping Unity Light Probes to a different pre-baked one

Viewed 1216

The Manual says (Light Probes) "can be swapped to a different pre-baked one at runtime."

http://docs.unity3d.com/ScriptReference/LightmapSettings-lightProbes.html

How is this done? gameObject.GetComponent<LightProbes>(); doesn't return the light probes of the attached gameObject and making a public LightProbes and manually assigning it in the editor doesn't do it either. Any help?

My current script:

using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class LightProbeTest : MonoBehaviour {

    LightProbes lPGroup1;
    LightProbes lPGroup2;

    void Start()
    {
        SceneManager.LoadSceneAsync("LP_Test1", LoadSceneMode.Additive);
        SceneManager.LoadSceneAsync("LP_Test2", LoadSceneMode.Additive);

        StartCoroutine(WaitForLoad());
    }

    IEnumerator WaitForLoad()
    {
        yield return new WaitForSeconds(2);

        GameObject go1 = GameObject.Find("LP_1");
        GameObject go2 = GameObject.Find("LP_2");
        lPGroup1 = go1.GetComponent<LightProbes>();
        lPGroup2 = go2.GetComponent<LightProbes>();

        StartCoroutine(SwapLightProbes());
    }

    IEnumerator SwapLightProbes()
    {
        LightmapSettings.lightProbes = lPGroup1;
        yield return new WaitForSeconds(1);

        LightmapSettings.lightProbes = lPGroup2;
        yield return new WaitForSeconds(1);

        StartCoroutine(SwapLightProbes());

    }
}
0 Answers
Related