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

public class Skimmer : MonoBehaviour {

	public enum side { LEFT, RIGHT };

	public side flip = side.RIGHT;

	public bool rotating;
	public int direction;

	public float currentRotation;
	public float MAX_ROTATE = 240f;

	// Use this for initialization
	void Start() {
		rotating = false;
		flip = side.RIGHT;
	}

	// Update is called once per frame
	void Update() {
		if (!rotating) {
			if (Input.GetAxis("Jump") > 0) {
				currentRotation = 0f;
				rotating = true;
				if (flip == side.RIGHT) {
					flip = side.LEFT;
				}
				else {
					flip = side.RIGHT;
				}
			}
			transform.position = new Vector3(transform.position.x, 0, transform.position.z);
		}
		else {
			if (currentRotation < 180f) {
				float rot = MAX_ROTATE * Time.deltaTime;
				currentRotation += rot;
				transform.parent.Rotate(0, 0, rot);
			}
			else {
				if (transform.localPosition.x < 0) {
					transform.position = transform.parent.position + transform.parent.right * -10;
				}
				else {
					transform.position = transform.parent.position + transform.parent.right * 10;
				}
				rotating = false;
				transform.position = new Vector3(transform.position.x, 0, transform.position.z);
			}
		}
	}
}
