2016-08-19 25 views
0

これで、テキストUIに文字列の配列を表示する必要があるquizzのようなものを作成しようとしています。問題は、私が正しく答えるとインスペクタで質問が更新されますが、ゲーム画面には表示されません。 Prob a noob mistake、すみません、私は初心者です。あなたが投稿したコードは動作するはずです(Unity)My Text UIが更新されない

public string[] quesitons = new string[] { "2+2 = ?", "1+1 = ?", "3+3 = ?" }; 
    public string[] answers = new string[] { "4", "2", "6" }; 
    public int i = 0; 

    [SerializeField] 
    private InputField _input; 

    //Main 
    public string currentQ; 
    public string currentA; 

    public Text questionText; 


    public void GetInput(string input) 
    { 
     if (input == answers[i]) 
     { 
      Debug.Log("Correct"); 
      i++; 
      questionText.text = quesitons[i]; 
      currentQ = quesitons[i]; 
      currentA = answers[i]; 
     } 
     else 
     { 
      Debug.Log("Wrong"); 
     } 
    } 

    void Start() 
    { 
     currentQ = quesitons[i]; 
     questionText.text = quesitons[i]; 

     currentA = answers[i]; 
    } 
} 

enter image description here

答えて

0

。たぶん、GetInput関数のテキスト更新ラインが欠けているのでしょうか?とにかくここにリファクタリングされたコードを投稿しました。 GetInput関数とStart関数を次のコードに置き換えてテストします。

public void GetInput(string input) { 
    if (input == currentA) { 
     Debug.Log("Correct"); 
     i++; 
     LoadQuestionAnswer(); 
    } 
    else { 
     Debug.Log("Wrong"); 
    } 
} 

void Start() { 
    LoadQuestionAnswer(); 
} 

void LoadQuestionAnswer() { 
    currentQ = quesitons[i]; 
    currentA = answers[i]; 
    questionText.text = currentQ; 
} 
関連する問題