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

public class EyeAnimation : MonoBehaviour {
    public enum State {Open, Closed};
    public TimerHelper timer;

    public State state = State.Open;

    public float timerLength = 5000;

    void Start() {
        timer = TimerHelper.Create();
    }

    void Update() {
        switch(state) {
            case State.Open:
                Update_Open();

                break;

            case State.Closed:
                Update_Closed();

                break;
        }
    }

    public void Update_Open() {
        Vector3 scale = transform.localScale;
        
        scale.y = scale.y * 0.95f + 1 * 0.05f;

        transform.localScale = scale;

        if (timer.GetMillisecs() > timerLength) {
            state = State.Closed;

            timerLength = Random.Range(3000, 10000);

            timer.Reset();
        }
    }

    public void Update_Closed() {
        Vector3 scale = transform.localScale;
        
        scale.y = scale.y * 0.95f + -1 * 0.05f;

        transform.localScale = scale;

         if (timer.GetMillisecs() > timerLength) {
            state = State.Open;

            timerLength = Random.Range(3000, 10000);

            timer.Reset();
        }
    }
}
