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

public class RadioControls : MonoBehaviour {

    [Range(0, 4)]
    public static float radioFrequency = 0;
    Vector3 mouseStart;
    Vector3 mouseOffset;
    public bool isDragging = false;
    public float frequencyChange = .4f;

   

    // Update is called once per frame
    void Update()
    {
        TurnDial();
        
        //Control audio with radioFrequency
        //Closer to the target ranges = less noise and better vocal audio
    }

    void TurnDial()
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(ray, out hit, 100f))
            {
                if (hit.transform.name == "Dial")
                {
                    Debug.Log("HIT THE TRANSFORM");
                    isDragging = true;
                    mouseStart = Input.mousePosition;
                }

            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            isDragging = false;
        }

        if (isDragging == true)
        {
            mouseOffset.x = Input.mousePosition.x - mouseStart.x;

            radioFrequency += mouseOffset.x * frequencyChange;
            radioFrequency = Mathf.Clamp(radioFrequency, 0, 4);

            mouseStart = Input.mousePosition;
        }
    }

   

}
