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

public class PlayerSonarScript : MonoBehaviour {

	float sonarScale;
	public float maxSonarScale = 12.0f;
	bool canSonar;

	public float sonarGrowSpeed = 1.1f;
	public float sonarShrinkSpeed = .99f;
	public float defaultSonarSize = 1.0f;
	public float sonarInterval = 2.0f;

	public GameObject sonarParticle;
	ParticleSystem sonarSystem;
	public GameObject sonarMask;
	Vector3 originalSize;
	float sonarTimer;

	// Use this for initialization
	void Start () {
		sonarScale = 1.0f;
		canSonar = true;
		sonarTimer = 0;
		originalSize = sonarMask.transform.localScale;
		sonarSystem = sonarParticle.GetComponent<ParticleSystem> ();
	}
	
	// Update is called once per frame
	void FixedUpdate () 
	{
		//if (canSonar && Input.GetKey (KeyCode.Space)
		//	&& gameObject.GetComponent<PlayerFlyScript>().SendDeathVar() == false) {
		//	sonarScale *= sonarGrowSpeed;
		//	if (sonarScale > maxSonarScale) {
		//		sonarScale = maxSonarScale;
		//		canSonar = false;
		//	}
		//}





		if (Input.GetKey (KeyCode.Space) && canSonar
			&& gameObject.GetComponent<PlayerFlyScript>().SendDeathVar() == false) {

			sonarSystem.Play ();
			canSonar = false;
			sonarTimer = sonarInterval;
		}
		else if (sonarTimer >= 0.0f)
		{
			sonarTimer -= Time.fixedDeltaTime;
			if (sonarTimer <= 0.0f)
				canSonar = true;
			//sonarScale *= sonarShrinkSpeed;
			//if (sonarScale <= defaultSonarSize) 
			//{
			//	sonarScale = defaultSonarSize;
			//	canSonar = true;
			//	sonarSystem.Stop ();
			//	particlesUsed = false;
			//}
		}
	}

	void Update()
	{
		sonarMask.transform.localScale = originalSize * sonarScale;
	}

	bool GiveCanSonar()
	{
		return canSonar;

	}
}
