using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class ProjoSuccess : MonoBehaviour
{

    public Light[] projos;

    public Color stable;
    public Color increasing;
    public Color decreasing;

    float lastFrameSuccess;
  
    void Start()
    {   
        projos = new Light[transform.childCount];
        for (int i = 0; i< transform.childCount; i++)
        {
            projos[i] =  transform.GetChild(i).GetComponent<Light>();
        }

        lastFrameSuccess = PlayerScript.success;
    }


    void Update()
    {
        if (PlayerScript.hardDancing)
        {
            gameObject.BroadcastMessage("NewTimer", 0.1f);
            ChangeProjoColors(increasing);
        }
        else if(PlayerScript.success == lastFrameSuccess)
        {
            gameObject.BroadcastMessage("NewTimer", 1.2f);
            ChangeProjoColors(stable);
        }
        else if (PlayerScript.success > lastFrameSuccess)
        {
            gameObject.BroadcastMessage("NewTimer", 0.1f);
            ChangeProjoColors(increasing);
        }
        else
        {
            gameObject.BroadcastMessage("NewTimer", 4f);
            ChangeProjoColors(decreasing);
        }

        lastFrameSuccess = PlayerScript.success;
    } 

 
    void ChangeProjoColors(Color desiredColor)
    {
        foreach (Light light in projos)
        {
            light.color = desiredColor;
        }
    }
  
}
