﻿using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Script.RAID100_Scrip
{
    public class WarmUpScreen : MonoBehaviour {
        public float Starting = 5;
        public float CurrentProcess;
        public Slider ProcesSlider;
        private float _speed = 30f;

        private Text _processText;
        private float _counter = 5;
        private GameObject _operateScreen;
        private GameObject _startupScreen;


        // Use this for initialization

        void Awake()
        {
            _startupScreen = GameObject.Find("Startup_Screen");
            _operateScreen = GameObject.Find("Operate_Screen");
        }
        void Start ()
        {
            _processText = GameObject.Find("Processing_Text").GetComponent<Text>();
            CurrentProcess = Starting;
        }
	
        // Update is called once per frame
        void Update ()
        {
        
	    
            CurrentProcess += _speed * Time.deltaTime;
            ProcesSlider.value = CurrentProcess;
            _counter += _speed * Time.deltaTime;
            if (CurrentProcess > 30f)
            {
                CurrentProcess = 0f;
                _processText.text = _processText.text != "SELFTEST" ? "SELFTEST" : "SELFTEST FINISHED!";
            }
            if (!(_counter > 60)) return;
            CurrentProcess = 30;
            _processText.text = "SELFTEST FINISHED!";
            StartCoroutine(WaitForSecond());
        }
        private IEnumerator WaitForSecond()
        {
            yield return new WaitForSeconds(1);
            _startupScreen.SetActive(false);
            _operateScreen.SetActive(true);
        }
    }
}
