using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimatedTextureOffset : MonoBehaviour {

	public Rigidbody Reference;
	MeshRenderer MR;
	Material mat;
	// Use this for initialization
	public float Speed = 0.1F;
	void Awake () {
		MR = GetComponent<MeshRenderer>();
		mat = MR.material;
	}
	
	// Update is called once per frame
	void Update () {
		Vector2 currOff = mat.GetTextureOffset("_MainTex");
		Vector2 refVel = new Vector2(Reference.velocity.x,Reference.velocity.z);
		mat.SetTextureOffset("_MainTex",currOff+refVel*Time.deltaTime*Speed);
	}
}
