// Start is called before the first frame update
    void Start()
    {
        // Start with the first page.
        LoadPage(currentPage);

        // Initialise the Gabors.
        for (int i = 0; i < stimOris.Length; i++)
        {
            Gabor stim = Instantiate(stimulusPrefab);
            stim.Init();
            stim.SetOrientation(stimOris[i]);
            stim.SetPosition(
                (int)System.Math.Round(stimX[i] * Screen.width),
                (int)System.Math.Round(stimY[i] * Screen.height));
            stim.SetClaimable(false);
            stim.SetMasked(false);
            stim.SetRotatable(false);
            stim.SetSelection(false);
            stim.SetVisible(false);
            stimList.Add(stim);
        }
    }
    // Functions to add and remove elements.
    private void LoadPage(int pageNumber)
    {
        // Update the button text.
        if (pageNumber == 0)
        {
            prevButtonText.color = new Color(0.7f, 0.7f, 0.7f);
        }
        else
        {
            prevButtonText.color = new Color(1.0f, 1.0f, 1.0f);
        }

        // Update the text.
        explanationText.text = pages[pageNumber];

        // Initialise the Gabors.
        for (int i = 0; i < stimOris.Length; i++)
        {
            Gabor stim = Instantiate(stimulusPrefab);
            stim.Init();
            stim.SetOrientation(stimOris[i]);
            stim.SetPosition(
                (int)System.Math.Round(stimX[i] * Screen.width),
                (int)System.Math.Round(stimY[i] * Screen.height));
            stim.SetClaimable(false);
            stim.SetMasked(false);
            stim.SetRotatable(false);
            stim.SetSelection(false);
            stim.SetVisible(false);
            stimList.Add(stim);
        }

        // Add the page-specific objects.
        switch (pageNumber)
        {
        // Nothing on the first page.
        case 0:
            break;

        // Nothing on the second page.
        case 1:
            break;

        // Nothing on the third page.
        case 2:
            break;

        // All claimable Gabors.
        case 3:
            for (int i = 0; i < stimList.Count; i++)
            {
                stimList[i].SetMasked(false);
                stimList[i].SetRotatable(false);
                stimList[i].SetSelection(false);
                stimList[i].SetClaimable(true);
                stimList[i].SetVisible(true);
            }
            selectionPhase = true;
            break;

        // Two player-claimed Gabors, and two opponent.
        case 4:
            for (int i = 0; i < stimList.Count; i++)
            {
                stimList[i].SetMasked(false);
                stimList[i].SetRotatable(false);
                stimList[i].SetSelection(false);
                stimList[i].SetClaimable(false);
                stimList[i].SetVisible(true);
                if (i < stimList.Count / 2)
                {
                    stimList[i].Claim(0, playerColour);
                }
                else
                {
                    stimList[i].Claim(1, opponentColour);
                }
            }
            break;

        // Fake trial 1
        case 5:
            StartCoroutine(PracticeTrial(stimDuration,
                                         maintenanceDuration));
            break;

        // Fake trial 2.
        case 6:
            StartCoroutine(PracticeTrial(stimDuration,
                                         maintenanceDuration));
            break;

        // Fake trial 4.
        case 7:
            StartCoroutine(PracticeTrial(stimDuration,
                                         maintenanceDuration));
            break;

        // End (nothing happens).
        case 9:
            break;

        // Default case.
        default:
            break;
        }

        // Update the latest page flip.
        lastPageFlip = Time.time;
    }