using UnityEngine;
using System.Collections;

public class CoreSpawnBullet : MonoBehaviour {

	public GameObject whiteSphere;
    public AudioClip spawnBulletSound;

//	private bool lerpWhiteSphere = false;
	private float lerpTime = 1f;
	private float currentLerpTime;
	private float startAlpha = 0.15f;
	private float endAlpha = 0.05f;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
		if (Dictionaries.dictionaries.startGame && !Dictionaries.dictionaries.gameOver)
		{
			if (Input.GetButtonDown("Fire1") && !Dictionaries.dictionaries.bulletExists)
			{
				Dictionaries.dictionaries.bulletExists = true;
				
				Instantiate(Resources.Load("Prefabs/bullet", typeof(GameObject)), transform.position, Quaternion.identity);

	            GetComponent<AudioSource>().PlayOneShot(spawnBulletSound);


	        }

		}

        //		if (lerpWhiteSphere)
        //		{
        currentLerpTime += Time.deltaTime;
			if (currentLerpTime > lerpTime)
			{
				currentLerpTime = 0;
				float alph = startAlpha;
				startAlpha = endAlpha;
				endAlpha = alph;
				lerpTime = Random.Range(0.1f, 1f);
			}
			
			float perc = currentLerpTime / lerpTime;
			Color col = whiteSphere.gameObject.GetComponent<SpriteRenderer>().color;
			col.a = Mathf.Lerp(startAlpha,endAlpha,perc);
			whiteSphere.GetComponent<SpriteRenderer>().color = col;

//		}

	}
}
