using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Petrol : Interactable
{
    public float collectionTime;
    public bool collecting;
    public bool looking;
    public int damagePerSecond;

    float currentTime;
     GameObject player;
    bool damaged;
    float time;

    public override void Interact()
    {
        collecting = true;
    }

    void Update()
    {        if(player==null)
        {
            player=PlayerDontDie.instance.transform.GetChild(2).gameObject;
        }
        if (collecting == true && looking == true)
        {
            Debug.Log("collecting");
            currentTime += Time.deltaTime;
            if (currentTime >= collectionTime)
            {
                GameManager.instance.petrolCollected = true;
                Debug.Log("CollectedPetrol");
                collecting=false;
            }
        }
        if (
            player.GetComponent<CharacterControl>().hitInfo.transform.name != null
            && player.GetComponent<CharacterControl>().hitInfo.transform.name == "petrol"
        )
        {
            looking = true;
        }
        else
        {
            looking = false;
        }


    }

    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            if (!damaged)
            {
                GameManager.instance.damagePlayer(damagePerSecond);
                damaged = true;
            }
            else
            {
                time += Time.deltaTime;
                if (time >= 1)
                {
                    time = 0;
                    damaged = false;
                }
            }
        }
    }
}
