void OnGUI()
    {
        GUIStyle style = new GUIStyle();

        style.normal.textColor = Color.white;


        //Border between the two images
        GUI.DrawTexture(new Rect(Screen.width / 2f - 1f, 0, 2, Screen.height), TexBorder, ScaleMode.ScaleToFit, true,
                        2f / Screen.height);

        if (_drawWhiteScreen)
        {
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), TexBorder, ScaleMode.ScaleToFit, true,
                            (float)Screen.width / Screen.height);
            return;
        }


        GUI.skin = ButtonSkin;


        string[] selectStr = { "Left", "Equal", "Right" };

        style.fontSize = 20;


#if DEBUGMODE
        GUILayout.BeginArea(new Rect(20, 10, 2500, 250));
        GUILayout.Label("Debug Mode", style);
        GUILayout.Label("Swapped = " + _arePositionsSwapped[_taskQInd], style);
        style.fontSize = 12;
        if (_arePositionsSwapped[_taskQInd])
        {
            GUILayout.Label("Left: " + _agentRight.Effort2String(), style);
            GUILayout.Label("Right: " + _agentLeft.Effort2String(), style);
        }
        else
        {
            GUILayout.Label("Left: " + _agentLeft.Effort2String(), style);
            GUILayout.Label("Right: " + _agentRight.Effort2String(), style);
        }


        GUILayout.Label("Hit: " + UserInfo.Hit);
        GUILayout.EndArea();
#endif
#if DEBUGMODE
        if (UserInfo.Hit >= 8 && _taskQInd >= 4)
        {
#else
        if (_submittedCnt >= _qCnt)   //STUDY IS OVER
        {
#endif

#if WEBMODE
            if (!_qualityPosted)
            {
                this.StartCoroutine(PostQualityCheck());
            }

            if (!_qualitySentToBrowser)                       //quality not sent to browser yet
            {
                Application.ExternalCall("sendQuality", "2"); //send quality to browser
                _qualitySentToBrowser = true;
            }
#endif
            style.fontSize             = 16;
            style.normal.textColor     = Color.black;
            _isSubmittedStr[_taskQInd] = "HIT is complete. Thank you!";
        }

        else   //STUDY CONTINUING

        {
            if (_agentLeft.gameObject && _agentRight.gameObject)
            {
                if (_agentLeft.AnimationOver() &&
                    _agentRight.AnimationOver())
                {
                    //Animation played at least once
                    _alreadyPlayed[_taskQInd] = true;
                }
            }
            if (GUI.Button(new Rect(Screen.width - 100, Screen.height - 60f, 100, 25), "Replay"))
            {
                UpdateParameters();
                ResetComponents(_agentLeft);
                ResetComponents(_agentRight);

                _persMapper.MapPersonalityToMotion(_agentLeft.GetComponent <PersonalityComponent>());
                _persMapper.MapPersonalityToMotion(_agentRight.GetComponent <PersonalityComponent>());

                Play(_agentLeft);
                Play(_agentRight);
            }

            style.fontSize         = 19;
            style.fontStyle        = FontStyle.Bold;
            style.normal.textColor = Color.black;
            GUI.Label(new Rect(5, Screen.height - 135f, 1000, 290), _questionNoStr, style);


            style.fontSize  = 15;
            style.fontStyle = FontStyle.Normal;
            GUILayout.BeginHorizontal();
            GUI.Label(new Rect(5, Screen.height - 110f, 1000, 290), "Which character looks ", style);
            style.fontStyle = FontStyle.Bold;

            GUI.Label(new Rect(170, Screen.height - 110f, 1000, 290), _personalityQuestionStr[_taskQInd], style);

            //GUI.Label( new Rect(165, Screen.height - 130f, 1000, 290), "MORE \"open to new experiences & complex \", and LESS \"conventional & uncreative\"", style);
            GUILayout.EndHorizontal();
            style.fontStyle = FontStyle.Normal;


            GUILayout.BeginArea(new Rect(Screen.width / 2f - 150, Screen.height - 80f, 1000, 290));
            _selectPersonality = GUILayout.SelectionGrid(_selectPersonality, selectStr, 3, GUILayout.Width(300));
            GUILayout.EndArea();



            GUI.color = Color.white;

#if !DEBUGMODE
            if (_agentLeft.AnimationOver() && _agentRight.AnimationOver() || _alreadyPlayed[_taskQInd])
#endif
            {
                if (GUI.Button(new Rect(Screen.width / 2f - 110, Screen.height - 45f, 200, 25), "Submit Answer"))
                {
                    if (_selectPersonality == -1)
                    {
                        _isSubmittedStr[_taskQInd] = "  Please select an answer first.";
                    }

                    else                                      //ANSWER SELECTED AND SUBMIT PRESSED
                    {
                        if (_isSubmitted[_taskQInd] == false) //NOT ALREADY SUBMITTED
                        {
                            _isSubmitted[_taskQInd] = true;
                            _submittedCnt++;
                        }

                        //change signs
                        if (_arePositionsSwapped[_taskQInd])  //Agent positions are swapped, left is on the right, and right is on the left
                        {
                            if (_selectPersonality == 0)      //left
                            {
                                _answerPersonality = 1;       //right
                            }
                            else if (_selectPersonality == 2) //right
                            {
                                _answerPersonality = -1;
                            }
                            else
                            {
                                _answerPersonality = 0; //equal
                            }
                        }
                        else                                  //positions not swapped
                        {
                            if (_selectPersonality == 0)      //left
                            {
                                _answerPersonality = -1;      //left
                            }
                            else if (_selectPersonality == 2) //right
                            {
                                _answerPersonality = 1;       //right
                            }
                            else
                            {
                                _answerPersonality = 0; //equal
                            }
                        }


#if WEBMODE
                        this.StartCoroutine(PostValues(_taskQInd + 1, _answerPersonality, _arePositionsSwapped[_taskQInd]));
#endif

                        //Move on to the next question
                        GetNextQuestion();
                        StartCoroutine(DrawWhiteScreen());
                        _answerPersonality = -1;
                        _selectPersonality = -1;
                    }
                }
            }
        }

        if (_submittedCnt >= _qCnt)
        {
            style.fontSize = 20;

            GUI.Label(new Rect(50, Screen.height - 80f, 800, 100), _isSubmittedStr[_taskQInd], style);
            //if (_quality >= 2)
            //   GUI.TextField(new Rect(180, Screen.height - 75f, 80, 20), UserInfo.Code,200);
        }
        else
        {
            GUI.Label(new Rect(Screen.width / 2f - 110, Screen.height - 35f, 500, 25), _isSubmittedStr[_taskQInd], style);
        }


        _questionNoStr = "Question " + (_taskQInd + 1) + " of " + (_qCnt) + ":";
    }

    void StopAnim(GameObject agent)
    {
        if (agent.GetComponent <Animation>().isPlaying)
        {
            agent.GetComponent <Animation>().clip.SampleAnimation(agent, 0); //instead of rewind
            agent.GetComponent <Animation>().Stop();
        }
    }

    void InitAgent(GameObject agent, string animName)
    {
        if (!agent)
        {
            return;
        }
        agent.GetComponent <AnimationInfo>().Reset(animName);
        agent.GetComponent <IKAnimator>().Reset();
        //agent.GetComponent<TorsoAnimator>().Reset();
        //Read values for the shape parameters
        //Need to call this only once

        agent.GetComponent <Animation>().enabled = true;
        agent.GetComponent <Animation>().Play(animName);
    }

    // remember to use StartCoroutine when calling this function!
    //qInd = actualqInd to store in the db
    IEnumerator PostValues(int qInd, int answerPersonality, bool arePositionsSwapped)
    {
        string resultURL = "https://fling.seas.upenn.edu/~fundad/cgi-bin/mturk3/putComparisonData.php";

        // Create a form object for sending high score data to the server
        var form = new WWWForm();

        form.AddField("userId", UserInfo.UserId);

        form.AddField("hit", UserInfo.Hit.ToString());
        form.AddField("qInd", qInd.ToString());  //starts from 1
        form.AddField("answer", answerPersonality.ToString());
        form.AddField("areSwapped", arePositionsSwapped ? "true" : "false");

        // Create a download object
        var download = new WWW(resultURL, form);



        // Wait until the download is done
        yield return(download);

        if (download.error != null)
        {
            Info = download.error;
            print("Error: " + download.error);
        }
        else
        {
            Info = "success " + download.text;
        }
    }
}