AnimateUV.cs 680 Bytes
using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Renderer))]
public class AnimateUV : MonoBehaviour
{
    public Vector2 speed;
    public bool animateOnStart = true;

    private Renderer _renderer;

	void Start ()
    {
        _renderer = GetComponent<Renderer>();

        if (animateOnStart)
            StartAnimation();	
	}

    private bool _isAnimating = false;

    public void StartAnimation()
    {
        _isAnimating = true;
    }

    public void StopAnimation()
    {
        _isAnimating = false;
    }
	
	void Update ()
    {
        if (!_isAnimating) return;

        _renderer.material.mainTextureOffset += speed * Time.deltaTime;
	}
}