using UnityEngine;
using System.Collections;

public class FoodCounter : MonoBehaviour {
    public static int meat = 0;

    public static float percentDone = 1.0f;

    public string level = "Dream3";

    public int amount = 6;
    public bool fromPrev = false;

    public bool requireTrigger = false;

    public GameObject goal;

    private int prev;

	// Use this for initialization
	void Start () {

        prev = meat;
	
	}
	
	// Update is called once per frame
	void Update () {
        if (!requireTrigger && haveFood()) {
            ScreenFader.instance.changeLevel(level);
        }

        if (goal != null && haveFood()) {
            goal.SetActive(true);
        }

        if (amount == 6) {
            percentDone = meat / 6.0f;
        } else {
            percentDone = (meat - prev) * 1.0f / amount;
        }


        if (percentDone > 1.0f) {
            percentDone = 1.0f;
        }


	}


    private bool haveFood() {
        if (fromPrev) {
            if (meat >= prev + amount) {
                return true;
            }
        } else {
            if (meat >= amount) {
                return true;
            }
        }

        return false;
    }

    void OnTriggerStay(Collider other) {
        if (other.tag == "Player" && haveFood()) {
            ScreenFader.instance.changeLevel(level);
        }
    }
}
