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

public class Player : MonoBehaviour 
{
	public float speed = 10;
	public Rigidbody rigidbody;

	public float size = 1;
	public float sizeIncrement = 0.1f;
	public float maxSize = 5;

	private Vector3 originalScale;

	public GameObject gameOver;
	public UnityEngine.UI.Text time;
	public UnityEngine.UI.Button restart;

	private float timePassed = 0;

	void Start ()
	{
		timePassed = 0;
		originalScale = transform.localScale;

		restart.onClick.AddListener (() => UnityEngine.SceneManagement.SceneManager.LoadScene (0));
	}

	void Update ()
	{
		time.text = String.Format("{0:0.00}", timePassed);
		timePassed += Time.deltaTime;
	}

	void FixedUpdate ()
	{
		float moveHorizontal = Input.GetAxis ("Horizontal");
		float moveVertical = Input.GetAxis ("Vertical");

		Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

		rigidbody.velocity = movement * speed;
	}

	void OnTriggerEnter (Collider other)
	{
		size += sizeIncrement;

		transform.localScale = originalScale * size;

		if (size >= maxSize)
		{
			gameOver.SetActive (true);

			Time.timeScale = 0;
		}
	}
}
