using UnityEngine;
using System.Collections;

public class BackGroundCtrl : MonoBehaviour {

	Transform player;
	PlayerController playerCtrl;
	Material backgoundMat;
	Vector3 offset;

	// Use this for initialization
	void Start () {
		player = GameObject.FindWithTag ("Player").transform;
		playerCtrl = player.GetComponent<PlayerController> ();
		backgoundMat = renderer.material;
		offset = Vector3.zero;
	}
	
	// Update is called once per frame
	void Update () {
		if(playerCtrl.enabled){
			offset -= player.right * playerCtrl.forwardSpeed * Time.deltaTime*0.03f;
			backgoundMat.SetTextureOffset("_MainTex", new Vector2(offset.x,offset.y));
		}
	}
}
