Last active
August 29, 2015 14:19
-
-
Save Fortyseven/0da41063b516b9eac967 to your computer and use it in GitHub Desktop.
Port of UVScroller.js to C# - Unity3D
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
/************************************************************************ | |
** 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