Skip to content

Instantly share code, notes, and snippets.

@delphic
Created April 11, 2019 11:04
Show Gist options
  • Save delphic/e74c045fb1dfe5c2e8a52185f0832dc4 to your computer and use it in GitHub Desktop.
Save delphic/e74c045fb1dfe5c2e8a52185f0832dc4 to your computer and use it in GitHub Desktop.
Simple Unity3D Scrolling Material Script
using UnityEngine;
[RequireComponent(typeof(MeshRenderer))]
public class ScrollingMaterial : MonoBehaviour
{
public float Speed;
float _uvFactor;
Material _materialToScroll;
void Awake()
{
_materialToScroll = GetComponent<MeshRenderer>().material;
float n = _materialToScroll.GetTextureScale("_MainTex").y;
float scale = transform.localScale.z;
_uvFactor = n / scale;
}
void Update()
{
_materialToScroll.mainTextureOffset = new Vector2(_materialToScroll.mainTextureOffset.x, _materialToScroll.mainTextureOffset.y + Time.deltaTime * Speed * _uvFactor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment