示例#1
0
    public void SetUpQuestion(uint num1, uint num2, uint numBlanks)
    {
        // Validate input
        if (num1 < 10 || num1 > 999 || num2 < 10 || num2 > 999 || numBlanks < 1 || numBlanks > 6)
        {
            Debug.LogError("Cannot init question box with these values: " + num1 + ", " + num2 + ", " + numBlanks);
            return;
        }

        // Set question text
        m_QuestionText.text = num1.ToString() + " * " + num2.ToString() + " = ???";

        // Initialize the grid of values
        uint[] draggableValues = m_QuestionBox.Init(num1, num2, numBlanks);

        // Shuffle the draggable objects array
        System.Random random = new System.Random();
        for (int i = m_DraggableObjects.Length - 1; i > 0; i--)
        {
            int randomIndex = random.Next(0, i + 1);

            DraggableObject temp = m_DraggableObjects[i];
            m_DraggableObjects[i]           = m_DraggableObjects[randomIndex];
            m_DraggableObjects[randomIndex] = temp;
        }

        // Set values of each draggable object
        for (int i = 0; i < m_DraggableObjects.Length; i++)
        {
            m_DraggableObjects[i].gameObject.SetActive(true);
            m_DraggableObjects[i].InitIfNeeded();

            if (i < numBlanks)
            {
                m_DraggableObjects[i].SetValue(draggableValues[i]);
            }
            else
            {
                m_DraggableObjects[i].gameObject.SetActive(false);
            }
        }

        // Disable the 'next' button
        m_NextButton.interactable = false;

        // Set the current amount of points to be awarded
        m_CurrentQuestionPoints = SCORE_SCALE;
    }