using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class GameEnding : MonoBehaviour {
	//Public
	[Header("Obiekty przypięte")]
	public GameObject	player		= null;
	public GameObject	cameraThird	= null;
	public GameObject	cameraSky	= null;
	public GameObject	cameraScene	= null;
	public GameObject	textInfo	= null;
	public GameObject	textStart	= null;
	
	//Private
	private bool		end			= false;
	private float		alphaTimer	= 0f;
	
	void Start() {
	
	}
	
	void Update() {
		if (Time.realtimeSinceStartup > 7f) {
			textStart.SetActive(false);
		}
			
		if (player.transform.position.y >= 42f) {
			end	= true;
		}
		if (end) {
			cameraThird.SetActive(false);
			cameraSky.SetActive(false);
			cameraScene.SetActive(true);
			
			player.rigidbody.AddForce(0f, 1000f, 0f);
			
			cameraScene.transform.LookAt(player.transform);
		}
		if (player.transform.position.y >= 2000f) {
			textInfo.SetActive(true);
			alphaTimer	+= Time.deltaTime;
			if (alphaTimer > 0.05f && textInfo.GetComponent<Text>().color.a < 1.0f) {
				textInfo.GetComponent<Text>().color	= new Color(
					0f, 0f, 0f, textInfo.GetComponent<Text>().color.a + 0.02f
				);
				alphaTimer	= 0f;
			}
		}
		
		if (Input.GetAxisRaw("Cancel") == 1f) {
			Application.Quit();
		}
	}
}
