[HOWTO] How To: Write Custom Command To Set Light Intensity
Posted: Sat Dec 18, 2021 8:23 am
This is a short custom sequencer command to change the intensity of a Light:
SequencerCommandLightIntensity.cs
You could change this to use a coroutine if you wanted to transition the light over a duration of time. If you do this, set the final light intensity in OnDestroy(), too, in case the command gets interrupted.
SequencerCommandLightIntensity.cs
Code: Select all
using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
/// <summary>
/// Sequencer command: LightIntensity(subject, intensity)
/// </summary>
public class SequencerCommandLightIntensity : SequencerCommand
{
private void Awake()
{
var subject = GetSubject(0);
var intensity = GetParameterAsFloat(1);
var light = (subject != null) ? subject.GetComponent<Light>() : null;
if (light != null) light.intensity = intensity;
Stop();
}
}
}