Skip to content

Instantly share code, notes, and snippets.

@Lorti
Last active December 20, 2015 10:31
Show Gist options
  • Save Lorti/6116385 to your computer and use it in GitHub Desktop.
Save Lorti/6116385 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class AnimateMaterial : MonoBehaviour {
public float scrollSpeedU = 0.0f;
public float scrollSpeedV = 0.25f;
public float amplitudeU = 0.0f;
public float amplitudeV = 0.0f;
void Update() {
float offsetU = 0.0f;
float offsetV = 0.0f;
if(amplitudeU > 0.0f) {
offsetU = amplitudeU * Mathf.Sin(scrollSpeedU * Time.time);
} else {
offsetU = Time.time * scrollSpeedU;
}
if(amplitudeV > 0.0f) {
offsetV = amplitudeV * Mathf.Sin(scrollSpeedV * Time.time);
} else {
offsetV = Time.time * scrollSpeedV;
}
renderer.material.SetTextureOffset("_MainTex", new Vector2(offsetU, offsetV));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment