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

public class GravityBroken : MonoBehaviour
{

    public static float Integrity = RepairableGravity.Integrity;
    public GameObject Player;
    public float IntIntegrity;
    public Rigidbody2D Prb;
    private Rigidbody2D Orb;
    public bool IsGravChanged = false;
    public static bool InterIsGravChanged;

    // Start is called before the first frame update
    void Start()
    {

    }

    private void Update()
    {
        Integrity = RepairableGravity.Integrity;
        InterIsGravChanged = IsGravChanged;
        IntIntegrity = Integrity;
    }

    // Update is called once per frame
    void FixedUpdate()
    {

        GameObject[] goWithTag = GameObject.FindGameObjectsWithTag("Objects");

        for (int i = 0; i < goWithTag.Length; ++i)
        {
            Orb = goWithTag[i].GetComponent<Rigidbody2D>();

            if (Integrity <= 10)
            {
                Vector3 theScale = Player.transform.localScale;

                theScale.y = -8;

                Player.transform.localScale = theScale;
                Prb.gravityScale = -1f;
                Orb.gravityScale = -1f;
                InterIsGravChanged = true;
            }
            else if (Integrity <= 50)
            {
                Vector3 theScale = Player.transform.localScale;

                theScale.y = 8;

                Player.transform.localScale = theScale;
                Prb.gravityScale = 0.5f;
                Orb.gravityScale = 0f;
                InterIsGravChanged = true;
            }
            else
            {
                Vector3 theScale = Player.transform.localScale;

                theScale.y = 8;

                Player.transform.localScale = theScale;
                Prb.gravityScale = 3f;
                Orb.gravityScale = 3f;
                InterIsGravChanged = false;
            }

        }


    }
}
