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

public class LevelGuageWrange : MonoBehaviour
{
    public GameObject gauge;
    public GameObject range;

    int ticks = 0;

    public float accpValue = 0;
    public float rangeVal = 0.1f;

    bool bounce = false;
    bool bounce2 = false;

    float value = 0;
    // Start is called before the first frame update
    void Start()
    {
        setRange(accpValue, rangeVal);
        setValue(value);
    }

    public void setValue(float newValue)
    {
        value = Mathf.Clamp01(newValue);

        this.gauge.transform.localPosition = new Vector3(calcPos(value), 0, 1);
        
    }

    private float calcPos(float v)
    {
        return 0.25f + (v * 3.52f);
    }

    public void setRange(float accpValue, float range)
    {       
        this.range.transform.localScale = new Vector3(range * 12, 1, 1);
        this.range.transform.localPosition = new Vector3(calcPos(Mathf.Clamp(accpValue, (range /2), 1- (range /2))), 0, 1);

    }

    // Update is called once per frame
    void Update()
    {
        ticks++;

        if (ticks > 10)
        {
            ticks = 0;

          //  rangeVal = Mathf.Clamp01(rangeVal + (bounce ? -0.01f : 0.01f)) ;

            if (accpValue == 0 || accpValue == 1)
            {
                bounce = !bounce;
            }
            
          //  setRange(accpValue, rangeVal);

           // setValue(value + (bounce2 ? -0.005f : 0.005f));

            if (value == 0 || value == 1)
            {
                bounce2 = !bounce2;
            }
        }
    }
}
