using UnityEngine;

public class UVScroller : MonoBehaviour {
    [SerializeField]
    private Vector2 scrollSpeed = Vector2.zero;
    [SerializeField]
    private Vector2 defaultOffset = Vector2.zero;
    [SerializeField]
    private Renderer _renderer = default;

    private Vector2 uv;

    void Awake(){
        uv = defaultOffset;
    }

    void Update(){
        uv += scrollSpeed * Time.smoothDeltaTime;
        if(uv.x >= 1.0f) uv.x -= 1.0f;
        else if(uv.x <= -1.0f) uv.x += 1.0f;
        if(uv.y >= 1.0f) uv.y -= 1.0f;
        else if(uv.y <= -1.0f) uv.y += 1.0f;
        _renderer.material.SetTextureOffset("_MainTex", uv);
    }
}
