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

public class PerfoBar : MonoBehaviour {
    public GameController controller;
    public RectTransform myTransf;
    public Image bar;
    public float R, G, B;
    public float performance;
	// Use this for initialization
	void Start () {
        myTransf = GetComponent<RectTransform>();
        bar = GetComponent<Image>();
	}
	
	// Update is called once per frame
	void Update () {
        performance = Mathf.Max(0,Mathf.Min(1,controller.performance / controller.totalPerformanceNeeded));
        R = 0;
        B = 0;
        if (performance <= 0.5) {
            R = Mathf.Lerp(1, 0, 2*performance);
            G = Mathf.Lerp(0, 1, 2 * performance);
        }
        else
        {
            G = Mathf.Lerp(1, 0, 2 * (performance-0.5f));
            B = Mathf.Lerp(0, 1, 2 *(performance-0.5f));
        }
        bar.color = new Color(R, G, B);
        
        myTransf.offsetMax = new Vector2(0, -355 * (1 - performance));
	}
}
