Simple Unity3D Scrolling Material Script
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; | |
[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