Exemple #1
0
    public void SelectionInit()
    {
        answerButtons.Clear();
        int        numberOfAnswers = 2;
        List <int> randomList      = new List <int>();

        string[] temp       = questionAnswer.Split('/');
        int      whileindex = 0;

        for (int i = 0; i < selectionButtons.Length; i++)
        {
            int randomnum = UnityEngine.Random.Range(0, 4);
            while (randomList.Contains(randomnum))
            {
                randomnum = UnityEngine.Random.Range(0, selectionButtons.Length);
                whileindex++;
            }
            randomList.Add(randomnum);
            string wrongChoiceGot = QuestionBuilder.GetRandomChoices();
            selectionButtons [randomnum].transform.GetChild(0).GetComponent <Text> ().text =
                i < numberOfAnswers ? temp [i].ToString().ToUpper() :
                wrongChoiceGot;
            if (i < numberOfAnswers)
            {
                answerButtons.Add(selectionButtons[randomnum]);
            }
        }
        answer1 = answerButtons [0].GetComponentInChildren <Text> ().text.ToUpper();
        answer2 = answerButtons [1].GetComponentInChildren <Text> ().text.ToUpper();
    }
    public void Init(bool isCorrect)
    {
        numberOfRemovedContainers = 0;
        string answer = "";

        if (isCorrect)
        {
            answer         = stackSwipeParent.questionAnswer;
            correctObject  = gameObject;
            this.isCorrect = true;
        }
        else
        {
            answer = QuestionBuilder.GetRandomChoices().Split('/') [0];
        }
        GetComponentInChildren <Text> ().text           = answer.ToUpper();
        GetComponentInChildren <Image> ().color         = Color.white;
        GetComponentInChildren <Image> ().raycastTarget = true;
        gameObject.SetActive(true);
        transform.SetSiblingIndex(UnityEngine.Random.Range(0, stackSwipeParent.stackSwipeContainers.Length));
    }