Forum rules - please read before posting.

optionsdata variable

Hi Chris,

I would like to store the sound effect volume to a global variable in AC.
I saw there is actionlist can set the values from options data but it seems no actionlist can read the sound effect volume value set from options.
Is there any easy way I can transfer the value of sound effect volume from options to a global variable?

Comments

  • You can get the SFX volume with the GetSFXVolume function:

    AC.Options.GetSFXVolume ();
    

    See the Manual's "Variable scripting" chapter for details on how to set a variable's value through script.

    To automate this, you can set a Float variable's Link to field to Custom Script, and then hook into the OnDownloadVariable / OnUploadVariable custom events to sync its value to the SFX volume. The Manual's "Linking with custom scripts" chapter in the Variables section covers this technique, but this should do it:

    using UnityEngine;
    
    namespace AC
    {
    
        public class SFXVariable : MonoBehaviour
        {
    
            public string variableName = "SFX Volume";
    
            private void OnEnable ()
            {
                EventManager.OnDownloadVariable += OnDownload;
                EventManager.OnUploadVariable += OnUpload;
            }
    
            private void OnDisable ()
            {
                EventManager.OnDownloadVariable -= OnDownload;
                EventManager.OnUploadVariable -= OnUpload;
            }
    
            private void OnDownload (GVar variable, Variables variables)
            {
                if (variable.label == variableName)
                {
                    variable.FloatValue = Options.GetSFXVolume ();
                }
            }
    
            private void OnUpload (GVar variable, Variables variables)
            {
                if (variable.label == variableName)
                {
                    Options.SetSFXVolume (variable.FloatValue);
                }
            }
    
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.