[HOWTO] How To: Write Custom Command To Set Light Intensity

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Write Custom Command To Set Light Intensity

Post by Tony Li »

This is a short custom sequencer command to change the intensity of a Light:

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();
        }
    }
}
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.
Post Reply