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

public class SpinnerEngine : MonoBehaviour
{
    public float xRotate, yRotate, zRotate;


    public GameObject spinner;


    private bool isGameStart;
    private float timeDelay, elapsedTime;
    
    // Start is called before the first frame update
    void Start()
    {

        isGameStart = false;
        zRotate = 50;
        timeDelay = 1;
        elapsedTime = 0;
    }

    private void FixedUpdate()
    {
        if (isGameStart)
        {
            elapsedTime += Time.fixedDeltaTime;
            if (elapsedTime > timeDelay)
            {
                elapsedTime = 0;
                StartCoroutine(SpinnerRotate());
            }
        }
    }


    // Update is called once per frame
    void Update()
    {
      


    }
    public void GameStatus(string status)
    {
        if(status == "Start")
        {
            isGameStart = true;
        }
        if (status == "Over")
        {
            isGameStart = false;
        }
    }
    IEnumerator SpinnerRotate()
    {
        int n = 20;
        while (n>0) 
        {
            spinner.transform.Rotate(xRotate, yRotate, zRotate);
            n -= 1;
            yield return new WaitForSeconds(0.05f);
        }        
    }

    private void OnTriggerExit(Collider other)
    {
        //other.name
    }
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log(other.name);
    }

}
