Created
April 11, 2019 11:04
-
-
Save delphic/e74c045fb1dfe5c2e8a52185f0832dc4 to your computer and use it in GitHub Desktop.
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