Rotation on one side with custom shader

Hi,

Im trying to make a custom shader to have a material stretch across multiple objects of different shapes (walls with holes voor doors, windows and normal walls)
I almost fixed it but the material is rotated 90 degrees now if I look at it from 1 side:

164682-shader.png

What am I missing? This is the shader:

Shader "WallShader" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _Scale("Texture Scale", Float) = 1.0
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
fixed4 _Color;
float _Scale;

struct Input {
    float3 worldNormal;
    float3 worldPos;
};

void surf (Input IN, inout SurfaceOutput o) {
    float2 UV;
    fixed4 c;

    if (abs(IN.worldNormal.x) > 0.5) {
        UV = IN.worldPos.yz; // side
        c = tex2D(_MainTex, UV* _Scale); // use WALL texture
    }
    else if (abs(IN.worldNormal.z) > 0.5) {
        UV = IN.worldPos.xy; // front
        c = tex2D(_MainTex, UV* _Scale); // use WALL texture
    }
        else if (abs(IN.worldNormal.y) > 0.5) {
        UV = IN.worldPos.xz; // back
        c = tex2D(_MainTex, UV* _Scale); // use WALL texture
    }
    else {
        UV = IN.worldPos.xz; // top
        c = tex2D(_MainTex, UV* _Scale); // use FLR texture
    }

    o.Albedo = c.rgb * _Color;
}
ENDCG
}

Fallback "Legacy Shaders/VertexLit"
}

I fixed it by making a second material wich was turned 90 degrees and used the same shader. Next time I won’t use the unity cube for walls but just pick 6 quads :stuck_out_tongue: