UnityEngine.Mathf.InverseLerp C# (CSharp) Method

InverseLerp() public static method

public static InverseLerp ( float from, float to, float value ) : float
from float
to float
value float
return float
        public static float InverseLerp(float from, float to, float value)
        {            
            if (from < to)
            {
                if (value < from)
                    return 0.0f;
                if (value > to)
                    return 1.0f;
            }
            else
            {
                if (value < to)
                    return 1.0f;
                if (value > @from)
                    return 0.0f;
            }
            return (value - from) / (to - from);
        }

Usage Example

コード例 #1
0
ファイル: AutoPupil.cs プロジェクト: lfe999/VamAutoPupil
        public float Update()
        {
            _currentTime = _currentTime + Time.deltaTime;
            if (_currentTime > _duration)
            {
                _currentTime = _duration;
            }

            // how far into the time are we?
            var percentageComplete = Math.InverseLerp(0, _duration, _currentTime);

            // return a new morph value that represents progressing _currentTime thorugh things
            return(_startValue + ((_targetValue - _startValue) * _easing(percentageComplete)));
        }
All Usage Examples Of UnityEngine.Mathf::InverseLerp