Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Clamp#

Math / Arithmetic / Clamp Between 0 and 1

  • Can Read

  • Cannot Write

Description#

Clamps the specified value between 0 and 1

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Clamp")]
    [Category("Math/Arithmetic/Clamp", "Between 0 and 1")]
    
    [Description("Clamps the specified value between 0 and 1")]
    [Image(typeof(IconContrast), ColorTheme.Type.Yellow)]
    
    [Keywords("Max", "Within", "Between", "Min", "Limit", "0", "1", "Ratio", "Normal")]
    
    [Serializable]
    public class TypeNumberMathClamp01 : TypeNumber
    {
        [SerializeField] private GetNumber m_Number = new GetNumber();

        public override double GetPreview(GameObject source) => Math.Clamp(this.m_Number.GetPreview(source), 0, 1);

        public override double Get(Args args)
        {
            double number = this.m_Number.Get(args);
            return Math.Clamp(number, 0, 1);
        }

        public override string ToString()
        {
            return $"Clamp01({this.m_Number})";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.