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

public class AparelhosScript : MonoBehaviour {


	public GameObject LoadProgressbar;
	public Image fillImg;

	private bool flagPressed;
	private bool flagPluged;

	public float timeAmt = 10;
	public float speed = 1;
	private float time;

	void Awake(){
		flagPressed = false;
		flagPluged = true;
		time = 0;

	}

	void Start(){
		LoadProgressbar.SetActive (flagPressed);
	}

	void Update(){
		if(flagPressed && flagPluged)
			LoadProgressbar.SetActive (flagPressed);
		else
			LoadProgressbar.SetActive (false);

		if (time < timeAmt && flagPressed && flagPluged) {
			time += speed * Time.deltaTime;
			//Debug.Log (time);
			fillImg.fillAmount = time / timeAmt;
		} else if (time >= timeAmt) {
			if (ObjectsSpawnScript.toList.Contains (gameObject.name) && flagPluged) {
				GCScript.pontos += 10;
				GCScript.cont++;
				Debug.Log ("Pontos" + GCScript.pontos);
			} else if(!ObjectsSpawnScript.toList.Contains (gameObject.name) && flagPluged){
				GCScript.pontos -= 15;
				Debug.Log ("Pontos" + GCScript.pontos);
			}
			flagPluged = false;
		}
		//Debug.Log ("flagPressed: "+flagPressed);
	}

	void OnMouseDown(){
		flagPressed = true;
		//Debug.Log (flagPressed);
	}

	void OnMouseUp(){
		flagPressed = false;
		time = 0;
		//Debug.Log (flagPressed);
	}
}
