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

public class WaypointMovement : MonoBehaviour {
	public GameObject boss;
	public Transform leftWall;
	public Transform rightWall;

	public float moveTime;
	private float startTime;
	private float moveSpeed = 1;

	public enum States{	Idle, MoveLeft, MoveRight };
	private States currentState = new States ();

	// Use this for initialization
	void Start () {
		startTime = Time.time;
		currentState = States.Idle;
	}
	
	// Update is called once per frame
	void Update () {

		//moveSpeed = (Time.time - startTime) / moveTime;
		
		switch (currentState) {
		case States.Idle:
			Idle ();
			break;
		case States.MoveLeft:
			MoveLeft ();
			break;
		case States.MoveRight:
			MoveRight ();
			break;
		default:
			break;
		}

	}

	void Idle() {	
		Debug.Log (Vector2.Distance (this.transform.position, boss.transform.position)); 	
		if (Vector2.Distance (this.transform.position, boss.transform.position) < 0.4f)
			currentState = States.MoveLeft;
	}

	void MoveLeft() {
		//this.transform.position = Vector2.MoveTowards (this.transform.position, leftWall.transform.position, 10);
		this.transform.position = Vector3.SlerpUnclamped (this.transform.position, leftWall.transform.position, moveSpeed * Time.deltaTime);
		Debug.Log(Vector2.Distance (this.transform.position, leftWall.transform.position));
			
		if (Vector2.Distance (this.transform.position, leftWall.transform.position) < 0.8f)
			currentState = States.MoveRight;
	}

	void MoveRight() {
		//this.transform.position = Vector2.MoveTowards (this.transform.position, rightWall.transform.position, 10);
		this.transform.position = Vector3.SlerpUnclamped (this.transform.position, rightWall.transform.position, moveSpeed * Time.deltaTime);
		Debug.Log(Vector2.Distance (this.transform.position, rightWall.transform.position));
					
		if (Vector2.Distance (this.transform.position, rightWall.transform.position) < 0.8f)
			currentState = States.MoveLeft;
	}
		
}
