平移和缩放比较好解决:
平移:
v2 = new Vector2(0f,v);
renderer.material.mainTextureOffset = v2;
v是一个浮点型的值。
缩放:
Vector2 size = new Vector2(3f, 3f);
renderer.material.SetTextureScale("_MainTex", size);
旋转就比较复杂:
需要自己学一个shader。
然后控制其中的一个值。
shader:
Shader "Custom/RotateUVs" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RotationSpeed ("Rotation Speed", Float) = 2.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
float _RotationSpeed;
void vert (inout appdata_full v) {
v.texcoord.xy -=0.5;
float s = sin ( _RotationSpeed);
float c = cos ( _RotationSpeed);
float2x2 rotationMatrix = float2x2( c, -s, s, c);
rotationMatrix *=0.5;
rotationMatrix +=0.5;
rotationMatrix = rotationMatrix * 2-1;
v.texcoord.xy = mul ( v.texcoord.xy, rotationMatrix );
v.texcoord.xy += 0.5;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
只要控制_RotationSpeed 的值即可。
源码已上传到资源里面。