What exactly is the difference between Tiling the material and Offset
of material?
Those parameters set by the inspector are used inside the shader to scale the texture coordinates.
A uniform float4
in the shader with the name of the texture and _ST suffix
is populated with those values.
For example considered the main texture:
float2 scaled_uv = tex.uv * _MainTex_ST.xy + _MainTex_ST.zw;
Let's say the offset basically translate the texture in the uv space meanwhile the scale, scales it.
mainTextureOffset: set the texture offset of the main texture (texture binded to the name _MainTex
inside a shader)
SetTextureOffset let you specify the texture name. SetTexureOffset(_MainTex, offset);
is equivalent to use the facility mainTextureOffset
.
An alternative is setting directly the uniform vector. The used convention for built-in shaders is using the suffix _ST to the texture name. So you can also use SetVector:
material.SetVector("_MainTex_ST", scaleAndOffset);
EDIT
For repeat the texture you have to modify the scale not the offset. If you set for example a scale of 2 along an uv axis you will obtain to repeat the texture twice along it.