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

public class EnemyLine : MonoBehaviour {

	public int lineLength = 3;
	public Vector3 movementVector = new Vector3 (1,0,0);
	int currentPosition;
	bool goingForward = true;

	// Use this for initialization
	void Start () 
	{
		InvokeRepeating ("MainMovement", 1.0f, 1.0f);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	void MoveForward ()
	{
		if (currentPosition < lineLength) 
		{
			transform.position += movementVector;
			currentPosition++;
		}
		else
		{
			transform.Rotate (180, 0, 0);
			goingForward = false;
		}
			
	}
	void MoveBackwards ()
	{
		if (currentPosition > 0) {
			transform.position -= movementVector;
			currentPosition--;
		} else {
			transform.Rotate (180, 0, 0);
			goingForward = true;
		}
	}
	void MainMovement(){
		if (goingForward) {
			MoveForward ();
		} else {
			MoveBackwards ();
		}
	}
	public void DisableFOV()
	{
		transform.GetChild (0).GetComponent<BoxCollider2D> ().enabled = false;
		transform.GetChild (0).GetComponent<SpriteRenderer> ().enabled = false;
		Invoke ("EnableFOV", 4f);

	}
	public void EnableFOV()
	{
		transform.GetChild (0).GetComponent<BoxCollider2D> ().enabled = true;
		transform.GetChild (0).GetComponent<SpriteRenderer> ().enabled = true;
	}
}
