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

public class QuestLVL3 : MonoBehaviour {

	public GameObject WaterBucket;
	public Text texto;
	public GameObject text;
	public GameObject fire;
	public GameObject finishObj;
	public int level;

	public bool hasWater;
	public bool isInTrigger;
	public bool isTakenOut;
	public bool isNearFire;

	// Use this for initialization
	void Start () {
		text.SetActive (false);
	}
	
	// Update is called once per frame
	void Update () {
		
		if(Input.GetKeyDown(KeyCode.F) && isInTrigger){
			PickUp ();
		} if(Input.GetKeyDown(KeyCode.F) && isNearFire){
			TakeOut ();
		}
	}

	void OnTriggerEnter(Collider other){
		if(other.tag == "Quest1"){
			texto.text = "Press F to pick up water bucket";
			text.SetActive (true);
			isInTrigger = true;

		} else if (other.tag == "Quest2" && hasWater){
			texto.text = "Press F to take out the fire";
			text.SetActive (true);
			isNearFire = true;
		}
	}

	void OnTriggerExit(Collider other){
		if(other.tag == "Quest1"){
			text.SetActive (false);
		} else if (other.tag == "Quest2"){
			text.SetActive (false);
		}
	}

	void PickUp(){
		Destroy (WaterBucket);
		hasWater = true;
		text.SetActive (false);
	}

	void TakeOut(){
		isTakenOut = true;
		fire.SetActive (false);
		finishObj.SetActive (true);
		level = 3;
		PlayerPrefs.SetInt ("level", level);
	}
		
}
