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

public class ParallaxTextureOffset : MonoBehaviour
{
	[SerializeField]
	private Renderer targetRenderer;

	[SerializeField]
	private Transform cameraTransform;

	[SerializeField]
	private float backPlateMovement;

	[SerializeField]
	private float frontPlateMovement;

	private void LateUpdate()
	{
		UpdateRenderer();
	}

	private void UpdateRenderer()
	{
		Vector2 minOffset = GetMinOffset();
		Vector3 maxOffset = GetMaxOffset();
		targetRenderer.sharedMaterial.SetTextureOffset("_BG0", minOffset);
		targetRenderer.sharedMaterial.SetTextureOffset("_BG1", Vector2.Lerp(minOffset, maxOffset, 1f / 3f));
		targetRenderer.sharedMaterial.SetTextureOffset("_BG2", Vector2.Lerp(minOffset, maxOffset, 2f / 3f));
		targetRenderer.sharedMaterial.SetTextureOffset("_BG2", maxOffset);
	}

	private Vector2 GetMinOffset()
	{
		return cameraTransform.position * frontPlateMovement;
	}

	private Vector2 GetMaxOffset()
	{
		return cameraTransform.position * backPlateMovement;
	}
}
