void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape) && !hasWiped)
        {
            circleWipe.setSceneToLoad(0);
            circleWipe.fadeOut();
            hasWiped = true;
        }

        // Set the current lap text to read the current lap

        redCurrentLapText.text  = "" + Mathf.Clamp(curLap[0], 1, lapCount);
        blueCurrentLapText.text = "" + Mathf.Clamp(curLap[1], 1, lapCount);

        // If there's a winner, scale up the winner text

        if (winner != -1)
        {
            winScale += (1 - winScale) * 0.025F;
            levelEnd.localRotation = Quaternion.Euler(0, 0, (1 - winScale) * 30);
            levelEnd.localScale    = new Vector3(winScale, winScale, 1);
        }

        // If the win screen has been on long enough, begin the circle wipe

        if ((winTime != -1) && (Time.time > winTime + winDelay) && (!hasWiped))
        {
            circleWipe.setSceneToLoad(0);
            circleWipe.fadeOut();
            hasWiped = true;
        }

        // Move the crosshairs around

        float lerpFactor = 0.25F;

        for (int i = 0; i < 2; i++)
        {
            RectTransform rect      = crossHairs[i].rectTransform;
            RectTransform planeRect = crossHairPlanes[i].rectTransform;
            bool          aimed     = squids[i].getPowerupAimed();

            Vector3 targPos = new Vector3(Screen.width * 0.5F, Screen.height * (0.75F - i * 0.5F), 0);
            if (aimed)
            {
                targPos = cameras[i].WorldToScreenPoint(squids[1 - i].transform.position);
            }
            rect.position = Vector3.Lerp(rect.position, targPos, lerpFactor);

            float totalScale = ((squids[i].getPowerupPhase() == 2 && squids[i].getPowerup() == 2) ? 1 : 0);
            float scale      = (aimed ? 1 : 0.5F) * totalScale;
            if (scale == 1)
            {
                scale *= 1 + (Mathf.Sin(Time.time * 15) * 0.075F);
            }
            rect.localScale      = Vector3.Lerp(rect.localScale, new Vector3(scale, scale, 1), lerpFactor);
            planeRect.localScale = Vector3.Lerp(planeRect.localScale, new Vector3(totalScale, totalScale, 1), lerpFactor);
        }
    }
    void Update()
    {
        // Input logic

        float lr, ud;

        lr          = Input.GetAxis("Move Horizontal 0");
        ud          = Input.GetAxis("Move Vertical 0");
        inputLRSign = lr < 0 ? -1 : (lr > 0 ? 1 : 0);
        inputUDSign = ud < 0 ? -1 : (ud > 0 ? 1 : 0);

        inputLeft       = (lr < 0 && (inputLRSign - inputLRSignPrev) == -1);
        inputRight      = (lr > 0 && (inputLRSign - inputLRSignPrev) == 1);
        inputUp         = (ud < 0 && (inputUDSign - inputUDSignPrev) == -1);
        inputDown       = (ud > 0 && (inputUDSign - inputUDSignPrev) == 1);
        inputFire       = Input.GetButtonDown("Fire 0");
        inputLRSignPrev = inputLRSign;
        inputUDSignPrev = inputUDSign;

        // Phase logic

        phaseTime       = Mathf.Clamp01((Time.time - phaseTimeStart) / phaseTimeLength);
        phaseTimeLength = (phasePrev == 0 ? 3.5F : 2);

        if (phaseTime == 1)
        {
            if (!phaseInitialized)
            {
                phaseButtons = UIPhases.transform.GetChild(phase).GetComponentsInChildren <ButtonController>();

                selected = lastSelected[phase];
                if (selected != -1)
                {
                    phaseButtons[selected].select();
                }

                phaseInitialized = true;
                UISounds[0].Play();
            }

            int prev;
            switch (phase)
            {
            case 0:                             // Flying in or quitting game
            case 4:                             // Exiting to a level
                break;

            case 1:                             // Main menu screen
                prev = selected;
                if (inputLeft)
                {
                    selected--;
                }
                if (inputRight)
                {
                    selected++;
                }
                if (selected < 0)
                {
                    selected = 2;
                }
                if (selected > 2)
                {
                    selected = 0;
                }
                if (selected != prev)
                {
                    UISounds[0].Play();
                    phaseButtons[prev].deselect();
                    phaseButtons[selected].select();
                }
                if (inputFire)
                {
                    lastSelected[phase] = selected;
                    UISounds[1].Play();

                    if (selected == 0)
                    {
                        toPhase(3);
                    }
                    else if (selected == 1)
                    {
                        toPhase(2);
                    }
                    else if (selected == 2)
                    {
                        circleWipe.setSceneToLoad(-1);
                        circleWipe.fadeOut();
                        toPhase(0);
                    }
                }
                break;

            case 2:                             // Level selection screen
                prev = selected;
                if (selected < 3)
                {
                    if (inputLeft)
                    {
                        selected--;
                    }
                    if (inputRight)
                    {
                        selected++;
                    }
                    if (selected < 0)
                    {
                        selected = 2;
                    }
                    if (selected > 2)
                    {
                        selected = 0;
                    }
                    if (inputUp || inputDown)
                    {
                        selected = 3;
                    }
                }
                else if (selected == 3)
                {
                    if (inputUp || inputDown)
                    {
                        selected = 1;
                    }
                }
                if (selected != prev)
                {
                    UISounds[0].Play();
                    phaseButtons[prev].deselect();
                    phaseButtons[selected].select();
                }
                if (inputFire)
                {
                    lastSelected[phase] = selected;
                    UISounds[1].Play();

                    if (selected < 3)
                    {
                        circleWipe.setSceneToLoad(selected + 1);
                        circleWipe.fadeOut();
                        toPhase(4);

                        hasLoadedOnce = true;
                    }
                    else
                    {
                        toPhase(1);
                    }
                }

                break;

            case 3:
                if (inputFire)
                {
                    UISounds[1].Play();
                    toPhase(1);
                }
                break;
            }
        }

        // Set camera position and rotation

        var rotHover = Quaternion.identity;

        rotHover *= Quaternion.Euler(Mathf.Sin(Time.time * 2.0F) * 0.15F, 0, 0);
        rotHover *= Quaternion.Euler(0, Mathf.Cos(Time.time * 1.5F) * 0.25F, 0);
        rotHover *= Quaternion.Euler(0, 0, Mathf.Sin(Time.time * 1.0F) * 0.6F);
        var posHover = Vector3.zero;

        posHover.x += Mathf.Cos(Time.time * 1.5F) * 0.03F;
        posHover.y += Mathf.Sin(Time.time * 2.5F) * 0.03F;
        posHover.z += Mathf.Cos(Time.time * 2F) * 0.03F;

        float bias = 0.8F;
        float t    = phaseTime;

        t *= t * t * (t * (t * 6 - 15) + 10);
        t /= ((1 / bias - 2) * (1 - t) + 1);

        camera.transform.position = Vector3.Lerp(cameraTargets[phasePrev].position, cameraTargets[phase].position, t) + posHover;
        camera.transform.rotation = Quaternion.Slerp(cameraTargets[phasePrev].rotation, cameraTargets[phase].rotation, t) * rotHover;
    }