Пример #1
0
    void Start()
    {
        Button w1 = Wrong1.GetComponent <Button>();
        Button w2 = Wrong2.GetComponent <Button>();
        Button w3 = Wrong3.GetComponent <Button>();
        Button r  = Right.GetComponent <Button>();

        w1.onClick.AddListener(delegate { Addstrike(Wrong1.GetComponentInChildren <Text>()); });
        w2.onClick.AddListener(delegate { Addstrike(Wrong2.GetComponentInChildren <Text>()); });
        w3.onClick.AddListener(delegate { Addstrike(Wrong3.GetComponentInChildren <Text>()); });
        r.onClick.AddListener(Win);
    }
Пример #2
0
    // Call This For New Question
    IEnumerator SetNewQuestion()
    {
        AnswerAGO.GetComponent <Button>().enabled = false;
        AnswerBGO.GetComponent <Button>().enabled = false;
        AnswerCGO.GetComponent <Button>().enabled = false;
        AnswerDGO.GetComponent <Button>().enabled = false;


        CountDownTime = 25;


        if (r >= questionData.questions.Count)
        {
            for (i = questionData.questions.Count - 1; i > 0; i--)                // get the count of the array an shuffle all the elements   begin from end to start of the array
            {
                r   = Random.Range(0, i);                                         //	get a random number from 0 to array count
                tmp = questionData.questions[i];                                  //	swap the random place (eg: 3) and assign it to tmp
                questionData.questions[i] = questionData.questions[r];            // swap the i(current number) with tmp
                questionData.questions[r] = tmp;                                  // swap the tmp with the value of i
            }
        }
        currentQuestion = questionData.questions[r++];


        RandomButtPos = Random.Range(1, 5);

        yield return(new WaitForSeconds(1f));



        //transition animations
        QuestionAnim.SetBool("NewQuestionAnimation", true);
        AnswersAnim.SetBool("NewAnswerAnimation", true);

        //reset color
        AnswerAGO.GetComponent <Image>().color = Color.white;
        AnswerBGO.GetComponent <Image>().color = Color.white;
        AnswerCGO.GetComponent <Image>().color = Color.white;
        AnswerDGO.GetComponent <Image>().color = Color.white;



        AnswerAGO.GetComponent <Button>().enabled = true;
        AnswerBGO.GetComponent <Button>().enabled = true;
        AnswerCGO.GetComponent <Button>().enabled = true;
        AnswerDGO.GetComponent <Button>().enabled = true;

        yield return(new WaitForSeconds(0.1f));

        //disable audience
        CorrectAnswerGO.GetComponent <Text>().text = " ";
        Wrong1.GetComponent <Text>().text          = " ";
        Wrong2.GetComponent <Text>().text          = " ";
        Wrong3.GetComponent <Text>().text          = " ";

        //make active
        AnswerAGO.SetActive(true);
        AnswerBGO.SetActive(true);
        AnswerCGO.SetActive(true);
        AnswerDGO.SetActive(true);

        //make active
        CharA.SetActive(true);
        CharB.SetActive(true);
        CharC.SetActive(true);
        CharD.SetActive(true);

        switch (RandomButtPos)
        {
        case 1:
            AnswerAGO.transform.localPosition = Button1Pos;
            AnswerBGO.transform.localPosition = Button2Pos;
            AnswerCGO.transform.localPosition = Button3Pos;
            AnswerDGO.transform.localPosition = Button4Pos;

            CorrectAnswerGO.transform.localPosition = Audience1Pos;
            Wrong1.transform.localPosition          = Audience2Pos;
            Wrong2.transform.localPosition          = Audience3Pos;
            Wrong3.transform.localPosition          = Audience4Pos;


            break;

        case 2:
            AnswerAGO.transform.localPosition = Button2Pos;
            AnswerBGO.transform.localPosition = Button1Pos;
            AnswerCGO.transform.localPosition = Button4Pos;
            AnswerDGO.transform.localPosition = Button3Pos;

            CorrectAnswerGO.transform.localPosition = Audience2Pos;
            Wrong1.transform.localPosition          = Audience1Pos;
            Wrong2.transform.localPosition          = Audience4Pos;
            Wrong3.transform.localPosition          = Audience3Pos;


            break;

        case 3:
            AnswerAGO.transform.localPosition = Button3Pos;
            AnswerBGO.transform.localPosition = Button4Pos;
            AnswerCGO.transform.localPosition = Button2Pos;
            AnswerDGO.transform.localPosition = Button1Pos;

            CorrectAnswerGO.transform.localPosition = Audience3Pos;
            Wrong1.transform.localPosition          = Audience4Pos;
            Wrong2.transform.localPosition          = Audience2Pos;
            Wrong3.transform.localPosition          = Audience1Pos;


            break;

        case 4:
            AnswerAGO.transform.localPosition = Button4Pos;
            AnswerBGO.transform.localPosition = Button3Pos;
            AnswerCGO.transform.localPosition = Button1Pos;
            AnswerDGO.transform.localPosition = Button2Pos;

            CorrectAnswerGO.transform.localPosition = Audience4Pos;
            Wrong1.transform.localPosition          = Audience3Pos;
            Wrong2.transform.localPosition          = Audience1Pos;
            Wrong3.transform.localPosition          = Audience2Pos;


            break;
        }

        //Adding Values To Text
        QuestionText.GetComponent <Text>().text = currentQuestion.questionText;

        AnswerAGO.GetComponentInChildren <Text>().text = currentQuestion.answerA;
        AnswerBGO.GetComponentInChildren <Text>().text = currentQuestion.answerB;
        AnswerCGO.GetComponentInChildren <Text>().text = currentQuestion.answerC;
        AnswerDGO.GetComponentInChildren <Text>().text = currentQuestion.answerD;

        yield return(new WaitForSeconds(0.1f));

        QuestionAnim.SetBool("NewQuestionAnimation", false);
        AnswersAnim.SetBool("NewAnswerAnimation", false);
    }