using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class controll : MonoBehaviour

{

    public GameObject layer1;

    public GameObject layer2;

    public GameObject layer3;

    bool iscycling = false;

    // Start is called before the first frame update

    void Start()

    {

        

    }


    // Update is called once per frame

    void Update()

    {

        

    }


    public void OnClickBUtton1()

    {

        layer1.SetActive(true);

        layer2.SetActive(false);

        layer3.SetActive(false);

    }

    public void OnClickBUtton2()

    {


        layer1.SetActive(false);

        layer2.SetActive(true);

        layer3.SetActive(false);

    }

    public void OnClickBUtton3()

    {

        layer1.SetActive(false);

        layer2.SetActive(false);

        layer3.SetActive(true);

    }

    public void OnClickBUtton4()

    {


        if(iscycling==false)

        {

            iscycling = true;

            StartCoroutine(cyclenow());

        

        }else

        {

            StopAllCoroutines();

            iscycling = false;

        }


    }


    private IEnumerator cyclenow()

    {

        while(iscycling==true)

        {

            OnClickBUtton1();


            yield return new WaitForSeconds(4);

            if (iscycling == false) break;

            OnClickBUtton2();


            yield return new WaitForSeconds(4);

            if (iscycling == false) break;

            OnClickBUtton3();


            yield return new WaitForSeconds(4);



        }

    }

}