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

public class ChangePlayer : MonoBehaviour {

	//Movimiento
	public GameObject characterToFollow;
	private Vector3 offset;

	public Transform flecha;
	//Para saber que saldra al disparar
	public GameObject flechaprefaps;

	//Zoom de la cámara
	int minZoom = 4;
	int maxZoom = 10;
	int zoomPower = 12;
	bool changePlayerPressed = false; 

	// Use this for initialization
	void Start () {
		Camera.main.orthographicSize = 6;
		offset = transform.position - characterToFollow.transform.position;
	}
	
	// Update is called once per frame
	void Update () {
		checkZoom ();

	}

	void LateUpdate(){
		transform.position = characterToFollow.transform.position + offset;
	}
		
	//Función que controla el zoom
	void checkZoom(){
		if (Input.GetKeyDown(KeyCode.Q)) {
			changePlayerPressed = !changePlayerPressed;
		}

		if(changePlayerPressed) // El usuario quiere cambiar de personaje, hagamos zoom out
		{
			Camera.main.orthographicSize = Camera.main.orthographicSize + zoomPower*Time.deltaTime;
			if(Camera.main.orthographicSize > maxZoom)
			{
				Camera.main.orthographicSize = maxZoom; // Max size
			}
		}


		if(changePlayerPressed == false) // El usuario terminó de seleccionar, hagamos zoom in
		{
			Camera.main.orthographicSize = Camera.main.orthographicSize - zoomPower*Time.deltaTime;
			if(Camera.main.orthographicSize < minZoom)
			{
				Camera.main.orthographicSize = minZoom; // Min size 
			}
		}
	}

	void disparar(){
		if (Input.GetButtonDown ("Fire1")) {
			print ("disparaste");
			Instantiate (flechaprefaps, flecha.position, flecha.rotation);
		}
	}
		
}
