laurenth-personal / lightmap-switching-tool

Tool that allows switching different baked lightmap sets on a unity scene at runtime.
MIT License
683 stars 90 forks source link

C# Script to Call Function to Switch Lighting #36

Closed SirRorick closed 1 year ago

SirRorick commented 1 year ago

I know this is a dumb question, but I can't seem to get this to work. What is the C# script to call a baked lightmap?

Instructions say "Call the public method LoadLightingScenario using an integer argument that represents the index of the lighting scenario"

I am not understanding how to achieve this, as I am trying the following:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SC1 : MonoBehaviour
{
void OnTriggerEnter(Collider other)
    {
            LevelLightmapData.LoadLightingScenario(1);
    }
}

I was able to get the rest of this working, I was able to add new scenes, and now I just need them to change upon collision with the script above. Thank you, and again, and I apologize for this dumb question. I know it is going to be something simple. (And I did search existing tickets/readme here and found nothing)

SirRorick commented 1 year ago

The error is: Assets\Scripts\SC1.cs(15,13): error CS0120: An object reference is required for the non-static field, method, or property 'LevelLightmapData.LoadLightingScenario(int)'

But I assume this is irrelevant because I am doing it wrong anyway.

SirRorick commented 1 year ago

Solved after a few hours of trial and error + countless searches. (I have a better understanding now)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SC1 : MonoBehaviour
{
    public LevelLightmapData lightData;

    public void OnTriggerEnter(Collider other)
    {
            lightData.LoadLightingScenario(0);
    }
}
laurenth-personal commented 1 year ago

Hello, Sorry I couldn't reply fast enough to help you out. I'm glad you found how to use it. This is probably a very good example code I could include in the readme file in the future.