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

public class BottleAnimations : MonoBehaviour {

	public GameObject Results;
	public GameObject HUD;
	public GameObject Menu;

	private float _timer1 = 0f;
	private float _timer2 = 0f;

	private float _heightDestination;
	private float _angleDestination;
	private float _yeahDestination;

	private const float _MIN_ = 0f;
	private const float _MAX_ = 0.15f;

	void Start () {
		
	}

	void Update () {
		if (_timer1 <= 0f) {
			_heightDestination = Random.Range (_MIN_, _MAX_);
			_timer1 = Random.Range (0.7f, 1.9f);
		} else {
			_timer1 -= Time.deltaTime;
			Vector3 position = transform.position;
			position.y = Mathf.Lerp (position.y, _heightDestination,Time.deltaTime);
			transform.position = position;
		}

		if (_timer2 <= 0f) {
			_angleDestination = Random.Range (230f, 310f);
			_yeahDestination = Random.Range (-25f, 25f);
			_timer2 = Random.Range (0.7f, 1.9f);
		} else {
			_timer2 -= Time.deltaTime;
			Vector3 eulers = transform.eulerAngles;
			eulers.x = Mathf.Lerp (eulers.x, _angleDestination, Time.deltaTime);
			eulers.y = Mathf.Lerp (eulers.y, _yeahDestination, Time.deltaTime);
			transform.eulerAngles = eulers;
		}
	}

	void OnCollisionEnter (Collision col) {
		if (col.gameObject.tag == "Enemy") {
			Results.SetActive (true);
			Results.transform.GetChild (0).gameObject.SetActive (true);
			Results.transform.GetChild (1).gameObject.SetActive (false);
			Results.transform.GetChild (2).gameObject.SetActive (false);
			HUD.gameObject.SetActive (false);
			Menu.transform.GetChild (1).gameObject.SetActive (true);
			gameObject.SetActive (false);
			col.gameObject.GetComponent<AudioSource> ().Play ();
		}
		if (col.gameObject.tag == "Hawaii") {
			Results.SetActive (true);
			Results.transform.GetChild (0).gameObject.SetActive (false);
			Results.transform.GetChild (1).gameObject.SetActive (true);
			Results.transform.GetChild (2).gameObject.SetActive (true);
			HUD.gameObject.SetActive (false);
			Menu.transform.GetChild (1).gameObject.SetActive (true);
			gameObject.SetActive (false);
		}
	}
}
