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

public class CoreGauge : MonoBehaviour
{
    GameObject needleSpriteRenderer;

    public float Value;
    

    private bool direction;

    private float tickTime = 0;

    // Start is called before the first frame update
    void Start()
    {
        needleSpriteRenderer = gameObject.transform.GetChild(1).gameObject;
        Value = 50;
    }

    public void setValue(float newValue)
    {
        Value = Mathf.Clamp(newValue, 0, 100);

        updateUI();
    }

    private void updateUI()
    {
        needleSpriteRenderer.transform.rotation = Quaternion.Euler(0, 0, 135 - ((Value / 100) * 270));
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        //setValue(Value + ((direction ? 1 :-1)* Time.deltaTime * 10));

        tickTime += Time.deltaTime;

        if (tickTime > 1)
        {
            direction = Random.value > 0.5;
            tickTime  = 0;
        }

        shake();
    }


    private void shake()
    {
        float deviance = Mathf.Pow(Mathf.Abs((Value - 50) / 100), 3) * 4;
        

        // No shake while devving
       // transform.position = new Vector3(Random.value * deviance, Random.value * deviance, 1);
    }
}

