How to apply a texture gradually depending on height?

Hey everyone.
I’ve been blocked with this for 2 days (I’m kinda new to shaders).
I want to apply a texture, something like this: 194584-imagen-2022-04-03-161049.png
And depending on MaxHeight and MinHeight values, which are coordinates from the world, apply the texture correctly to the middle pixels (by correcly I mean that the effect of gradient should be seen complete, from red to purple).
This is what I’ve got so far:

Shader "Custom/Gradiente"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _MinHeight("Min Height", Float) = 0.4
        _MaxHeight("Max Height", Float) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
            float3 worldPos;
        };
        
        sampler2D _MainTex;
        half _Glossiness;
        half _Metallic;
        half _MaxHeight;
        half _MinHeight;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {

            if(IN.worldPos.y < _MinHeight){
                fixed4 c = tex2D (_MainTex, half2(0,0));
                o.Albedo = c.rgb;
                o.Alpha = c.a;
            }
            else if(IN.worldPos.y > _MaxHeight ){
                    fixed4 c = tex2D (_MainTex, half2(1,1));
                    o.Albedo = c.rgb;
                    o.Alpha = c.a;
                }
                else{
                    fixed4 c = tex2D (_MainTex, IN.uv_MainTex);   
                    o.Albedo = c.rgb;
                    o.Alpha = c.a;
                }
            
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

And this is how the final result SHOULD look like:

You just need to use worldPos.y as the input UVs to the texture sample:

void surf (Input IN, inout SurfaceOutputStandard o)
{
    // Remap worldPos.y to go from [0,1] between _MinHeight and _MaxHeight
    float y = (IN.worldPos.y - _MinHeight) / (_MaxHeight - _MinHeight);
    float2 uv = float2 (y, 0);
    fixed4 c = tex2D (_MainTex, uv);
    o.Albedo = c.rgb;
    o.Alpha = c.a;
    o.Metallic = _Metallic;
    o.Smoothness = _Glossiness;
}

Make sure to use it as the x-coordinate on the UVs as the gradient goes horizontally in the texture. If you need it to clamp at the edges, you can either set the texture wrap mode to clamp or saturate() the UVs.