Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.