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

public class PowerControlScript : MonoBehaviour
{
    bool powerControlMode = true;
    //bool upgradeMode = false;
    int maxTotalPower = 3;
    int totalPower;

    public Slider TotalPowerDisplay;
    public Text modeDisplay;

    void Start()
    {
        totalPower = maxTotalPower;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (powerControlMode)
            {
                powerControlMode = false;
            }
            else
            {
                powerControlMode = true;
                modeDisplay.text = "Power Control Mode";
            }
        }
        RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.forward);
        if (hit && powerControlMode == true)
        {
            if (hit.collider.gameObject.GetComponent<PoweredObject>() != null)
            {
                if (Input.GetKeyDown(KeyCode.Mouse0) && totalPower > 0)
                {
                    bool b = hit.collider.gameObject.GetComponent<PoweredObject>().IncreasePower();
                    if (b)
                    {
                        totalPower--;
                    }

                }
                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    bool b = hit.collider.gameObject.GetComponent<PoweredObject>().DecreasePower();
                    if (b)
                    {
                        totalPower++;
                    }
                }
            }
        }
        TotalPowerDisplay.maxValue = maxTotalPower;
        TotalPowerDisplay.value = totalPower;
    }
}

