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

public class ShieldOn : MonoBehaviour {

    public GameObject playerShield;

    private float onShieldTime;

    public Image imageTimer;

    bool collided = false;

   	void Start () {

    }
	
	void Update () {
        imageTimer.fillAmount = onShieldTime / 20f;

        if (collided) {
            onShieldTime -= Time.deltaTime;
        }

        if (onShieldTime <= 0f) {
            playerShield.SetActive(false);
            onShieldTime = 0f;
        }
    }


    private void OnTriggerEnter2D(Collider2D collision) {
        if (collision.tag == "Shield") {
            playerShield.SetActive(true);
            collided = true;
            onShieldTime = 20f;
            ScoreCount.instance.CountScore(+10);
            Destroy(collision.gameObject);
        }
    }
}
