public IEnumerator loadNewQuestion_ie(int amount, string category, string difficulty, string type)
    {
        string url = api + "?amount=" + amount + "&category=" + category + "&difficulty=" + difficulty + "&type=" + type;

        Debug.Log(url);
        WWW www = new WWW(url);

        yield return(www);

        if (www.error != null)
        {
            Debug.LogError("ERROR DOWNLOADING QUESTION: " + www.error);
        }
        else
        {
            string wwwString = www.text;
            wwwString = wwwString.Replace("{\"response_code\":0,\"results\":[", "");
            wwwString = wwwString.Remove(wwwString.Length - 2);
            Debug.Log(wwwString);
            //q = (questionObj)JsonUtility.FromJson(wwwString, typeof(questionObj));
            q = JsonUtility.FromJson <questionObj>(wwwString);
            q.setAnswers();
            //Debug.Log(q.incorrect_answers[0]);
        }

        //ui.setQuestion(q);
    }
Exemplo n.º 2
0
 public void showCorrectAnswer(questionObj q)
 {
     answerBackground[0].color = Color.red;
     answerBackground[1].color = Color.red;
     answerBackground[2].color = Color.red;
     answerBackground[3].color = Color.red;
     answerBackground[q.correct_answer_id].color = Color.green;
     answerText[q.correct_answer_id].color       = Color.black;
     footerText  = "The correct answer is \"" + q.answers_letters[q.correct_answer_id] + ". " + q.answers[q.correct_answer_id] + "\"";
     footer.text = footerText;
 }
Exemplo n.º 3
0
    public void setQuestion(questionObj q)
    {
        question.text = q.question;

        answerPrecent[0].gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
        answerPrecent[1].gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
        answerPrecent[2].gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
        answerPrecent[3].gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);

        if (q.type == "boolean")
        {
            answerBackground[0].enabled = false;
            answerBackground[1].enabled = true;
            answerBackground[2].enabled = false;
            answerBackground[3].enabled = true;

            answerPrecent[0].enabled = false;
            answerPrecent[1].enabled = true;
            answerPrecent[2].enabled = false;
            answerPrecent[3].enabled = true;

            footerText = "To submit your answer, type #T or #F in the chat.\nType #help for more info.";
        }
        else
        {
            answerBackground[0].enabled = true;
            answerBackground[1].enabled = true;
            answerBackground[2].enabled = true;
            answerBackground[3].enabled = true;

            answerPrecent[0].enabled = true;
            answerPrecent[1].enabled = true;
            answerPrecent[2].enabled = true;
            answerPrecent[3].enabled = true;

            footerText = "To submit your answer, type #A, #B, #C, or #D in the chat.\nType #help for more info."; // To use 50 / 50, type #5050 in chat.  To trust the crowd, type #crowd in chat.
        }

        int i = 0;

        while (i < 4)
        {
            answerText[i].text        = "<b>" + q.answers_letters[i] + "</b>. " + q.answers[i];
            answerText[i].color       = Color.white;
            answerBackground[i].color = Color.blue;
            i++;
        }
        footer.text = "<b>Submit your answer now. (30)</b>\n" + footerText;
        Debug.Log(q.correct_answer_id);
    }