docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class IntGlobalVariable

    An IVariable implementation that holds a single integer value.

    Inheritance
    object
    Variable<int>
    IntVariable
    IntGlobalVariable
    Implements
    IVariableValueChanged
    IVariable
    ISerializationCallbackReceiver
    Inherited Members
    Variable<int>.ValueChanged
    Variable<int>.Value
    Variable<int>.GetSourceValue(ISelectorInfo)
    Namespace: UnityEngine.Localization.SmartFormat.GlobalVariables
    Assembly: Unity.Localization.dll
    Syntax
    [Serializable]
    [Obsolete("Please use UnityEngine.Localization.SmartFormat.PersistentVariables.IntVariable instead (UnityUpgradable) -> UnityEngine.Localization.SmartFormat.PersistentVariables.IntVariable")]
    public class IntGlobalVariable : IntVariable, IVariableValueChanged, IVariable, ISerializationCallbackReceiver
    Remarks

    This class is serializable. You can use it in the Inspector. Modifying its Value triggers the ValueChanged event, automatically updating any Smart Strings displaying the value.

    Examples

    The following example shows how to create a BoolVariable and use it in a LocalizedString.

    public class BoolVariableSample : MonoBehaviour
    {
        // Assuming the Localizing String is set in the inspector and is in the format "The door is {door-state:choose(Open|Closed)}"
        public LocalizedString localizedString;
        BoolVariable m_Variable;
    
        void Start()
        {
            m_Variable = new BoolVariable { Value = false };
            localizedString.Add("door-state", m_Variable);
        }
    
        public void OpenDoor() => m_Variable.Value = true;
        public void CloseDoor() => m_Variable.Value = false;
    }

    The following example shows how to create a SByteVariable and use it in a LocalizedString.

    public class SByteVariableSample : MonoBehaviour
    {
        // Assuming the Localizing String is set in the inspector and is in the format "The value is {my-value}"
        public LocalizedString localizedString;
        SByteVariable m_Variable;
    
        void Start()
        {
            m_Variable = new SByteVariable { Value = 1 };
            localizedString.Add("my-value", m_Variable);
        }
    
        public void SetValue(sbyte value) => m_Variable.Value = value;
    }

    The following example shows how to create a DoubleVariable and use it in a LocalizedString.

    public class DoubleVariableSample : MonoBehaviour
    {
        // Assuming the Localizing String is set in the inspector and is in the format "The road is {length}m long."
        public LocalizedString localizedString;
        DoubleVariable m_Variable;
    
        public double Length
        {
            get => m_Variable.Value;
            set => m_Variable.Value = value;
        }
    
        void Start()
        {
            m_Variable = new DoubleVariable { Value = 100 };
            localizedString.Add("length", m_Variable);
        }
    }

    Implements

    IVariableValueChanged
    IVariable
    ISerializationCallbackReceiver
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)