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

public class GravChange : MonoBehaviour
{


    private Rigidbody2D rb;


    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }


    // Update is called once per frame
    void FixedUpdate()
    {
        bool IsCloseEnough = CheckCloseToTag("Gravity", 10);

        if (IsCloseEnough)
        {
            rb.gravityScale = 0.5f;
        }
        else
        {
            if (!GravityBroken.InterIsGravChanged)
            {
                rb.gravityScale = 3;
            }
        }

    }

    bool CheckCloseToTag(string tag, float minimumDistance)
    {
        GameObject[] goWithTag = GameObject.FindGameObjectsWithTag(tag);

        for (int i = 0; i < goWithTag.Length; ++i)
        {
            if (Vector3.Distance(transform.position, goWithTag[i].transform.position) <= minimumDistance)
                return true;
        }

        return false;

    }
}