IEnumerator ResetActive3()
    {
        yield return(new WaitForSeconds(0.2f));

        if (active1box != null)
        {
            GeneralControls.ResetBox(active1box);
        }
        active1box      = null;
        active1boxchild = null;
        active1         = false;
        if (active2box != null)
        {
            GeneralControls.ResetBox(active2box);
        }
        active2box      = null;
        active2boxchild = null;
        active2         = false;
        if (active3box != null)
        {
            GeneralControls.ResetBox(active3box);
        }
        active3box      = null;
        active3boxchild = null;
        active3         = false;
    }
    // Update is called once per frame
    void Update()
    {
        remaining.text = "Remaining Time: " + Timeremaining + "s";

        if (Input.touchCount > 0)
        {
            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                //temp box
                tempbox = GeneralControls.checkTouch(Input.GetTouch(0).position);
            }
        }
        if (Input.GetMouseButtonDown(0))
        {
            //same as above
            tempbox = GeneralControls.checkTouch(Input.mousePosition);
        }
        if ((!active1) &&
            (tempbox != null) &&
            (!levelcheck) &&
            (!defeated) &&
            (tempbox != temp1) &&
            (tempbox != temp2) &&
            (tempbox != temp3))
        {
            active1         = true;
            active1box      = tempbox;
            tempbox         = null;
            active1boxchild = GeneralControls.TurnOnBox(active1box, active1, false, false);
            count           = 1;

            //if star and completes stage
            if (GeneralControls.LampOne(active1boxchild, currentcolor))
            {
                active2 = true;
                active3 = true;
                count   = 0;
                StartCoroutine("Lamp1");
            }
            //checks if the box is with in the lamp colors
            if ((!GeneralControls.CheckBox(currentcolor, active1box)) && (count != 0) &&
                (!GeneralControls.LampOne(active1boxchild, currentcolor)))
            {
                count = 0;


                StartCoroutine("ResetActive1");
            }
        }
        if ((active1) &&
            (!active2) &&
            (tempbox != active1box) &&
            (tempbox != null) &&
            (!levelcheck) &&
            (!defeated) &&
            (tempbox != temp1) &&
            (tempbox != temp2) &&
            (tempbox != temp3))
        {
            active2         = true;
            active2box      = tempbox;
            tempbox         = null;
            active2boxchild = GeneralControls.TurnOnBox(active2box, active1, active2, false);
            count           = 2;

            if ((!GeneralControls.CheckBox(currentcolor, active2box)) ||
                (GeneralControls.DuplicateBox(active1boxchild, active2boxchild)) ||
                active2box == null)
            {
                count = 0;



                StartCoroutine("ResetActive2");
            }
        }
        if ((active1) &&
            (active2) &&
            (!active3) &&
            (tempbox != active1box) &&
            (tempbox != active2box) &&
            (tempbox != null) &&
            (!levelcheck) &&
            (!defeated) &&
            ((GeneralControls.Lampinteger(currentcolor) == 3) ||
             (active2boxchild.layer == 20)) &&
            (tempbox != temp1) &&
            (tempbox != temp2) &&
            (tempbox != temp3))
        {
            active3         = true;
            active3box      = tempbox;
            tempbox         = null;
            active3boxchild = GeneralControls.TurnOnBox(active3box, active1, active2, active3);
            count           = 3;

            if ((!GeneralControls.CheckBox(currentcolor, active3box)) ||
                (GeneralControls.DuplicateBox(active1boxchild, active2boxchild)) ||
                (GeneralControls.DuplicateBox(active3boxchild, active2boxchild)) ||
                (GeneralControls.DuplicateBox(active3boxchild, active1boxchild)) ||
                active3box == null)
            {
                count = 0;



                StartCoroutine("ResetActive3");
            }
        }
        if ((active1boxchild == null) &&
            (active2boxchild != null))
        {
            BoxArray = GameObject.FindGameObjectsWithTag("boxes");

            for (int i = 0; i < BoxArray.Length; i++)
            {
                if ((BoxArray[i] != null) &&
                    (BoxArray[i] != temp1) &&
                    (BoxArray[i] != temp2) &&
                    (BoxArray[i] != temp3))
                {
                    GeneralControls.ResetBox(BoxArray[i]);
                }
            }
            active1box      = null;
            active1boxchild = null;
            active1         = false;
            active2box      = null;
            active2boxchild = null;
            active2         = false;
            count           = 0;
            oneTime         = 0;
        }
        if (((active1boxchild == null) &&
             (active2boxchild != null) &&
             (active3boxchild != null)) ||
            ((active1boxchild != null) &&
             (active2boxchild == null) &&
             (active3boxchild != null)) ||
            ((active1boxchild == null) &&
             (active2boxchild == null) &&
             (active3boxchild != null)))
        {
            BoxArray = GameObject.FindGameObjectsWithTag("boxes");

            for (int i = 0; i < BoxArray.Length; i++)
            {
                if ((BoxArray[i] != null) &&
                    (BoxArray[i] != temp1) &&
                    (BoxArray[i] != temp2) &&
                    (BoxArray[i] != temp3))
                {
                    GeneralControls.ResetBox(BoxArray[i]);
                }
            }
            active1box      = null;
            active1boxchild = null;
            active1         = false;
            active2box      = null;
            active2boxchild = null;
            active2         = false;
            active3box      = null;
            active3boxchild = null;
            active3         = false;
            count           = 0;
            oneTime         = 0;
        }
        if (count != 0)
        {
            //checks to see if lamp is complete
            if (GeneralControls.Finalchecklamp(currentcolor, count, active2boxchild))
            {
                if ((count == 2) &&
                    (GeneralControls.LampTwo(active1boxchild, active2boxchild, currentcolor)))
                {
                    count = 0;
                    StartCoroutine("Lamp2");
                }

                if ((count == 3) &&
                    (GeneralControls.LampThree(active1boxchild, active2boxchild, active3boxchild, currentcolor)))
                {
                    count = 0;
                    StartCoroutine("Lamp3");
                }
            }
        }
        if ((lamp.Length == 0) && (levelcheck != true))
        {
            victory1   = true;
            levelcheck = true;
            if (levelcheck)
            {
                StartCoroutine("LampDies");
            }
        }
        if ((tempbox == victory) &&
            (victory1))
        {
            Sound.instance.buttonclick();
            StartCoroutine(loadinglevel("level11"));
            tempbox = null;
        }

        if ((tempbox == defeated1) &&
            (defeated))
        {
            Sound.instance.buttonclick();
            StartCoroutine(loadinglevel("level10"));
            tempbox = null;
        }
        if ((tempbox == mainmenu1) || (tempbox == mainmenu2) ||
            (tempbox == zeromainmenu))
        {
            tempbox = null;
            Sound.instance.buttonclick();
            StartCoroutine(loadinglevel("LevelSelectorDesolateOasis"));
        }
        if (tempbox == zerodefeated)
        {
            tempbox = null;
            Sound.instance.buttonclick();
            StartCoroutine(loadinglevel("level10"));
        }
        if ((Timeremaining == 0) &&
            (!defeated) &&
            (!victory1))
        {
            defeated = true;
            oneTime  = 1;
            boxes    = GameObject.FindGameObjectsWithTag("boxes");
            StartCoroutine("zeroremains");
        }

        if ((!defeated) &&
            (!victory1) &&
            (oneTime == 0) &&
            (temp1 == null) &&
            (temp2 == null) &&
            (temp3 == null))
        {
            oneTime  = 1;
            boxArray = GameObject.FindGameObjectsWithTag("boxes");
            if ((!GeneralControls.CheckCombination(boxArray, currentcolor)))
            {
                defeated = true;
                StartCoroutine("defeat");
            }
        }
    }