Home>
Heading text

On the 10th line in the Update function, the entered text (inputstring) and the answer to the question (Answer) are equal (the correct answer is entered), but False is judged and else is executed. I will end up. I wonder why,,,?
For some reason, only the final question is judged correctly.

using UnityEngine;
using UnityEngine.UI;
public class Quiz: MonoBehaviour
{
    public GameObject Sen_Obj = null;
    // Mysterious type that receives input
    public InputField inputfield;
    // string to receive input
    public string input string;
    // Declare a quiz list
    public string [] QuizList;
    // Declare a string to store the problem statement
    public string Question;
    // Declare a string to store the answer
    public string Answer;
    // Declare the number of questions to store the number of questions
    public int NoQ;
    // Declare the problem number
    public int QNo;
    void Start ()
    {
        // Instance to store the text file
        TextAsset QuizFile = new TextAsset ();
        // Store the entire text in a quiz file
        QuizFile = Resources.Load ("Quiz", typeof (TextAsset)) as TextAsset;
        // Convert quiz file to string
        string QuizText = QuizFile.text;
        // Split text with line breaks and store in quiz list
        QuizList = QuizText.Split ('\ n');
        // Store the number of questions
        NoQ = QuizList.Length;
        // Reset problem number to 1
        QNo = 1;
        // It seems that it stores the component
        inputfield = inputfield.GetComponent<InputField>();
        // Display the first question
        GetQuiz (1);
    }
    void Update ()
    {
        // Correct/incorrect judgment when enter is pressed
        if (Input.GetKeyDown (KeyCode.Return))
        {
            // get input
            inputstring = inputfield.text;
            if (inputstring! = null)
            {
                // Correct answer
                if (inputstring == Answer)
                {
                    Debug.Log ("Correct!");
                }
                //Incorrect answer
                else else
                {
                    Debug.Log (incorrect);
                }
                // Show next issue
                if (QNo<NoQ)
                {
                    // Add +1 to the question number to display the next question
                    QNo ++;
                    GetQuiz (QNo);
                    // Clear the answer column
                    inputfield.text = "";
                }
                // At the time of the final problem
                else else
                {
                    Debug.Log ("Problem finished");
                    ChangeText ("The problem is over");
                }
            }
        }
    }
    // Show the problem
    void ChangeText (string Sentence)
    {
        Text Sen_Tex = Sen_Obj.GetComponent<Text>();
        Sen_Tex.text = Sentence;
    }
    // (argument) Display the question
    void GetQuiz (int QuizNum)
    {
        // Problem * Store the answer in a string
        string QAString = QuizList [QuizNum --1];
        Split by // *
        string [] QAList = QAString.Split ('*');
        // Assign to Question and Answer
        Question = QAList [0];
        Answer = QAList [1];
        //display
        ChangeText (Question);
    }
}