Skip to content

Instantly share code, notes, and snippets.

@Fortyseven
Last active August 29, 2015 14:19
Show Gist options
  • Save Fortyseven/0da41063b516b9eac967 to your computer and use it in GitHub Desktop.
Save Fortyseven/0da41063b516b9eac967 to your computer and use it in GitHub Desktop.
Port of UVScroller.js to C# - Unity3D
/************************************************************************
** UVScrollerEx.cs
**
** Ported from UVScroller.js
*************************************************************************/
using UnityEngine;
[ExecuteInEditMode]
public class UVScroller : MonoBehaviour
{
public float ScrollSpeed = 1.0f;
public float MainOffsetX = 0.0f;
public float MainOffsetY = 0.0f;
public Texture UseCustomTex = null;
public string CustomTexName = "";
private Renderer _renderer;
private Vector2 _offs;
public void Start()
{
_renderer = GetComponent<Renderer>();
_offs = new Vector2( 0, 0 );
}
public void Update()
{
float offset = Time.time * ScrollSpeed;
_offs.x = MainOffsetX * offset;
_offs.y = MainOffsetY * offset;
_renderer.sharedMaterial.SetTextureOffset( UseCustomTex ? CustomTexName : "_MainTex", _offs );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment