SequencerCommandVolume.cs
Code: Select all
using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandVolume : SequencerCommand
{
public void Start()
{
Stop(); // Immediately go to OnDestroy.
}
public void OnDestroy()
{
// Do it here so "required" commands run even if the line is skipped:
var subject = GetSubject(0, speaker);
var audioSource = (subject != null) ? subject.GetComponent<AudioSource>() : null;
var volume = GetParameterAsFloat(1);
if (audioSource == null)
{
if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Volume(" + GetParameters() + ") can't find audio source.", subject);
}
else
{
if (DialogueDebug.logInfo) Debug.Log("Dialogue System: Volume(" + GetParameters() + ").", subject);
audioSource.volume = volume;
}
}
}
}