Last active
August 29, 2015 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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