using UnityEngine;
using System.Collections;

public class RestrictionMove : MonoBehaviour 
{
	[Header("Speed")]
	public float speedX;
	public float speedY;
	//public float speedZ;

	//Variables para la función MaxMinChecker()
	[Header("X")]
	public float maxX;
	public float minX;

	[Header("Y")]
	public float maxY;
	public float minY;

	bool reachMaxX = false;
	bool reachMinX = true;
	bool reachMaxY = false;
	bool reachMinY = true;



	void Start()
	{
		reachMinX = true;
		reachMinY = true;
	}


	void Update () 
	{
		MaxMinCheckerX ();
		MaxMinCheckerY ();
		ConstantMoveOfAnAbjectX ();
		ConstantMoveOfAnAbjectY ();
	}
	
	
	public void ConstantMoveOfAnAbjectX()
	{

		if (reachMinX == true) 
		{
			transform.Translate (speedX * Time.deltaTime, 0, 0, Camera.main.transform);
		} 
		else if (reachMaxX == true) 
		{
			transform.Translate (speedX * -Time.deltaTime, 0, 0, Camera.main.transform);
		}


		//ESCOGE DE ENTRE LOS CODIGOS DE ABAJO PARA INCLUIRLOS EN EL if

		//transform.Translate(valorX * Time.deltaTime, valorY * Time.deltaTime, valorZ * Time.deltaTime, Camera.main.transform);

		//transform.Translate(Vector3.up * Time.deltaTime, Camera.main.transform);
		
		//transform.Translate(0, 0, Time.deltaTime);
		//transform.Translate(0, Time.deltaTime, 0, Space.World);
		
		//transform.Translate(Vector3.forward * Time.deltaTime);
		//transform.Translate(Vector3.up * Time.deltaTime, Space.World);
	}



	public void ConstantMoveOfAnAbjectY()
	{

		if (reachMinY == true) 
		{
			transform.Translate (0, speedY * Time.deltaTime, 0, Camera.main.transform);
		} 
		else if (reachMaxY == true) 
		{
			transform.Translate (0, speedY * -Time.deltaTime, 0, Camera.main.transform);
		}


		//ESCOGE DE ENTRE LOS CODIGOS DE ABAJO PARA INCLUIRLOS EN EL if

		//transform.Translate(valorX * Time.deltaTime, valorY * Time.deltaTime, valorZ * Time.deltaTime, Camera.main.transform);
		
		//transform.Translate(Vector3.up * Time.deltaTime, Camera.main.transform);
		
		//transform.Translate(0, 0, Time.deltaTime);
		//transform.Translate(0, Time.deltaTime, 0, Space.World);
		
		//transform.Translate(Vector3.forward * Time.deltaTime);
		//transform.Translate(Vector3.up * Time.deltaTime, Space.World);
	}



	void MaxMinCheckerX()
	{
		if (gameObject.transform.localPosition.x >= maxX) 
		{
			reachMaxX = true;
			reachMinX = false;
		} 
		else if (gameObject.transform.localPosition.x <= minX) 
		{
			reachMaxX = false;
			reachMinX = true;
		}
	}


		void MaxMinCheckerY()
		{
			if (gameObject.transform.localPosition.y >= maxY) 
			{
				reachMaxY = true;
				reachMinY = false;
			} 
			else if (gameObject.transform.localPosition.y <= minY) 
			{
				reachMaxY = false;
				reachMinY = true;
			}
		}


}









