Please refer to this Answer.
DMGregory script is working for me, although I have a problem I can't fix because I don't talk shader :)
The tiling will be applied correctly on geometry aligned on XY plane BUT if you have an orthogonal plane (let's think a common room with 4 walls), the texture will stretch through the plane. Do you know how to fix that? I would like to apply world coord to texture for all 4 walls. (Note that the "plane" I am using is a simple quad made of 2 triangles.)
Here is a screenshot:
EDIT: After digging a while I found this guy here which did something similar.
My guess was to use the plane normal to set up the texture but, not knowing the syntax, the result was... well nothing :)
Here you can see the shader. Anyway, as pointed by DMGregory, it doesn't work for all wall angles. Notice the one in diagonal, shown in the picture.
Shader "Diffuse - Worldspace"
{
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 WALLSIDE texture
}
else if(abs(IN.worldNormal.z)>0.5)
{
UV = IN.worldPos.xy; // front
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 "VertexLit"
}