Spin a texture in just any material -is it possible?

I was just looking for more ways to UV animate textures, but with limited success. All I want to do is access the matrix and spin it. I don’t know if most shaders support modifying the matrix, but I just wanted to check and make sure I wasn’t missing something. I would really just like to be able to modify any material in general.

Here is the code I’ve been messing with:

var mtrx:Matrix4x4;
private var okString:String;
var spinme:Material;

function Start() {
mtrx=spinme.GetMatrix(“_Rotation”);

}

function Update() {

var rot=Quaternion.Euler(Time.time30,Time.time30,Time.time*30);

mtrx=Matrix4x4.TRS(Vector3.zero,rot,Vector3(1,1,1) );
spinme.SetMatrix(“_Rotation”,mtrx);

}

Materials are supports matrix deformations, but shader should support it too. by default, shaders are doesn’t. so you need a little shader modifications to do it.

example shader that supports texture matrix deformations

Shader "Unity Answers/Diffuse with material matrix"
{
	Properties
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 200

		CGPROGRAM
		#pragma surface surf Lambert
	
		sampler2D _MainTex;
		float4x4 _Matrix0;

		struct Input
		{
			float2 uv_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o)
		{
			fixed4 c = tex2D(_MainTex, mul(_Matrix0, float4(IN.uv_MainTex, 0, 0)).xy);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	}
	Fallback "VertexLit"
}

example script that deformates texture using matrix

using UnityEngine;
using System.Collections;
public class Matrix2Material : MonoBehaviour
{
    public Material Material2SetMatrix;
    void Update()
    {
        Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, Time.time * 10f), Vector3.one);
        Material2SetMatrix.SetMatrix("_Matrix0", m);
    }
}