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

public class PaddleController : MonoBehaviour {

    private float baseRotationSpeed = 0.2f;
    float rotateValue = 0;
    float currCountdownValue;
    [SerializeField] private Rigidbody2D myRigidbody;
    void Start ()
    {

        StartCoroutine(StartCountdown());
    }

    // Update is called once per frame
    void Update()
    {
        rotateValue = 0;
        rotateValue += Input.GetAxis("TriggerLeft2"); 
        rotateValue -= Input.GetAxis("TriggerRight2");
        //rotateValue -= Input.GetAxis("Horizontal");

        rotateValue += baseRotationSpeed;
        
       
    }

    void FixedUpdate()
    {
        transform.Rotate(new Vector3(0, 0, rotateValue));
        
    }

    public IEnumerator StartCountdown(float countdownValue = 5)
    {
        currCountdownValue = countdownValue;
        while (currCountdownValue > 0)
        {
            yield return null;
            currCountdownValue -= Time.deltaTime;
        }

        baseRotationSpeed = Random.Range(-0.3f,0.3f);
        if(baseRotationSpeed > -0.1f && baseRotationSpeed < 0)
        {
            baseRotationSpeed = -0.1f;
        }
        else if(baseRotationSpeed < 0.1f && baseRotationSpeed >= 0)
        {
            baseRotationSpeed = 0.1f;
        }
        StartCoroutine(StartCountdown(Random.Range(0.5f,3f)));
    }
}
