Skip to content

Instantly share code, notes, and snippets.

@Crushy
Last active August 29, 2015 13:56
Show Gist options
  • Save Crushy/9081038 to your computer and use it in GitHub Desktop.
Save Crushy/9081038 to your computer and use it in GitHub Desktop.
Animates UVs. Useful for some effects that require UV maps to wobble around and such. Might expand this later.
using UnityEngine;
using System.Collections;
/// <summary>
/// Choose the material's index and plot away how it's UVs should behave
/// </summary>
[RequireComponent(typeof(Renderer))]
public class AnimateUVs : MonoBehaviour {
[System.Serializable]
public class MaterialDisplacement {
public int material;
public string targetTexture = "_MainTex";
public AnimationCurve x = AnimationCurve.Linear(0,0,0,0);
public AnimationCurve y = AnimationCurve.Linear(0,0,0,0);
}
public MaterialDisplacement[] materialDisplacement;
public void OnRenderObject() {
foreach (MaterialDisplacement mat in materialDisplacement) {
renderer.sharedMaterials[mat.material].SetTextureOffset( mat.targetTexture, new Vector2( mat.x.Evaluate( Time.realtimeSinceStartup ), mat.y.Evaluate( Time.realtimeSinceStartup ) ) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment