using UnityEngine;
using System.Collections;

public class OgettiScorrevoli : MonoBehaviour {

	public float scrollSpeed;
	public float textureTiling;
	public int Order;

	void Start () 
	{
		GetComponent<Renderer>().sortingOrder = Order;
	}

	void Update () 
	{
		var mr = GetComponent<MeshRenderer>();

		var mat = mr.material;

		var offset = mat.mainTextureOffset;

		mat.mainTextureScale = new Vector2(textureTiling, textureTiling);

		offset.x = transform.position.x * scrollSpeed/100f;
		offset.y = 0;

		mat.mainTextureOffset = offset;
	}
}
