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

In Range#

Math / Numbers / In Range

  • Can Read

  • Cannot Write

Description#

Returns True when a number is between a minimum and a maximum value

Parameters#

Name Description
Number The number that is checked
Min The lowest value of the range
Max The highest value of the range
Inclusive Whether a number exactly equal to Min or Max is inside the range

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("In Range")]
    [Category("Math/Numbers/In Range")]

    [Description("Returns True when a number is between a minimum and a maximum value")]
    [Image(typeof(IconContrast), ColorTheme.Type.Yellow, typeof(BadgeHash))]

    [Parameter("Number", "The number that is checked")]
    [Parameter("Min", "The lowest value of the range")]
    [Parameter("Max", "The highest value of the range")]
    [Parameter("Inclusive", "Whether a number exactly equal to Min or Max is inside the range")]

    [Keywords("Between", "Within", "Clamp", "Limit", "Interval", "Bounds")]

    [Serializable]
    public class TypeBoolMathNumbersInRange : TypeBool
    {
        [SerializeField] private GetNumber m_Number = new GetNumber();
        [SerializeField] private GetNumber m_Min = new GetNumber(0f);
        [SerializeField] private GetNumber m_Max = new GetNumber(1f);
        [SerializeField] private GetBool m_Inclusive = new GetBool(true);

        public override bool GetPreview(GameObject source) => InRange(
            this.m_Number.GetPreview(source),
            this.m_Min.GetPreview(source),
            this.m_Max.GetPreview(source),
            this.m_Inclusive.GetPreview(source)
        );

        public override bool Get(Args args) => InRange(
            this.m_Number.Get(args),
            this.m_Min.Get(args),
            this.m_Max.Get(args),
            this.m_Inclusive.Get(args)
        );

        private static bool InRange(double number, double min, double max, bool inclusive)
        {
            if (min > max) ValueUtils.Swap(ref min, ref max);

            return inclusive
                ? number >= min && number <= max
                : number > min && number < max;
        }

        public override string ToString()
        {
            return $"{this.m_Number} in ({this.m_Min}, {this.m_Max})";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.