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

public class AccelerometerFunctions : MonoBehaviour
{
    public Text Label;

    public float DetectingShake = 1.5f;

    public const float DETECTINTERVALSEC = 0.3f;
    
    private Vector3 oldAcceleration;

    private void Start()
    {
        StartCoroutine(CompareAcceleration());
    }

    private IEnumerator CompareAcceleration()
    {
        oldAcceleration = Input.acceleration;

        while (true)
        {
            Label.text = "" + Vector3.Distance(Input.acceleration, oldAcceleration);

            if (Vector3.Distance(Input.acceleration, oldAcceleration) > DetectingShake)
                GameManager.Singleton.ShakeCommand();

            oldAcceleration = Input.acceleration;

            yield return new WaitForSeconds(DETECTINTERVALSEC);
        }
    }
    
}
