示例#1
0
    public void SubmitAnswer()
    {
        Debug.Log("GameManager.SubmitAnswer");

        try
        {
            // Get current prefab gameobject
            GameObject answerRowPrefab = answers[currentAnswerIndex];

            // Get prefab script (reference to renderer and material
            AnswerRow answerRow = answerRowPrefab.GetComponent <AnswerRow>();

            if (answerRow.IsValid())
            {
                Debug.Log("GameManager.SubmitAnswer Valid Answer");
                var answerStatus = answerRow.CheckAnswer(solution);

                if (answerStatus == AnswerStatus.Correct)
                {
                    // Win case
                    ShowHideWinMessage(true);

                    // Clear answers
                    ClearAnswers();
                }
                else
                {
                    if (currentAnswerIndex + 1 >= GameManager.TRY_COUNT)
                    {
                        // You lose, exceeded try count
                        ShowHideLoseMessage(true);

                        // Clear answers
                        ClearAnswers();
                    }
                    else
                    {
                        // Create next row
                        GameObject newAnswerRowPrefab = GetNewAnswerRow(currentTopLeft);

                        // Get script
                        AnswerRow newAnswerRow = newAnswerRowPrefab.GetComponent <AnswerRow>();

                        // Init new row with correct answers
                        newAnswerRow.InitCorrectAnswers(answerRow, solution);

                        // Add to answers collection
                        answers[++currentAnswerIndex] = newAnswerRowPrefab;
                    }
                }
            }
            else
            {
                Debug.Log("GameManager.SubmitAnswer Invalid Answer");
            }
        }
        catch (Exception ex)
        {
            Debug.Log(string.Format("GameManager.SubmitAnswer Error: {0}", ex.Message));
        }
    }