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

public class Eletron : MonoBehaviour
{
	[SerializeField]
	private GameObject eletron;

	private Vector3 distance;
	private Vector3 rotationVector2;

	private bool movedUp;
	private bool movedDown;

	public float speed = 200;
	public float speedMove = 500f;
	public float passPos = 3.15f;
	public float minPos = 5.0f;
	public float maxPos = 10.0f;
	private float rot;

	public float fracJourney;

	void Start()
	{
		distance = new Vector3(minPos, 0.0f, 0.0f);
		eletron.transform.position = distance;
		distance = new Vector3(passPos, 0.0f, 0.0f);
	}

	void moveUp(Vector3 posStart)
	{
        eletron.transform.localPosition += distance;
    }

	void moveDown()
	{
		eletron.transform.localPosition -= distance;
	}

	void Update()
	{
        
		float fracJourney = speedMove * Time.deltaTime;
        
		if(Input.GetAxis("Horizontal") != 0)
		{ 
			rot = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
			rotationVector2 = new Vector3(0.0f, 0.0f, rot);
			transform.Rotate(rotationVector2);
		}
        
		if(Input.GetAxis("Vertical") == 0)
		{
			movedUp = false;
			movedDown = false;
		}

		if(Input.GetAxis("Vertical") > 0 && eletron.transform.localPosition.x < maxPos && movedUp == false)
		{
			moveUp(eletron.transform.localPosition);
			movedUp = true;
		}

		if(Input.GetAxis("Vertical") < 0 && eletron.transform.localPosition.x > minPos && movedDown == false)
		{
			moveDown();
			movedDown = true;
		}

	}
}
