Skip to content

Instantly share code, notes, and snippets.

@ibra
Last active August 12, 2021 17:51
Show Gist options
  • Save ibra/03a9af05e40cc3a381c9e7a669dfc5cb to your computer and use it in GitHub Desktop.
Save ibra/03a9af05e40cc3a381c9e7a669dfc5cb to your computer and use it in GitHub Desktop.
Infinite Scrolling Material In Unity in 20 Lines
using UnityEngine;
namespace IbraUtils.Scrolling
{
public class InfiniteScroll : MonoBehaviour
{
private Material _material;
private Vector2 _scrollVelocity;
[SerializeField] private float xVelocity, yVelocity;
private void Awake () =>
_material = GetComponent<Renderer>().material;
private void Start () =>
_scrollVelocity = new Vector2(xVelocity, yVelocity);
private void Update() =>
_material.mainTextureOffset += _scrollVelocity * Time.deltaTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment