2017-05-29 34 views
-3

当他们得到正确答案时,我不知道如何增加numberquestion。 如果您有能力,请告诉我如何在每次提供正确答案时增加numberquestion1,以便知道何时转到下一个问题。如何增加静态int数?

using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 

注:我使用的是统一的游戏引擎^^^^^

public class TextControl : MonoBehaviour { 

List<string> questions = new List<string>() {"When does time fly?","When does time?","When does?"}; 

List<string> CorrectAnswer = new List<string>() {"3","3","3"}; 

public static string SelectedAnswer; 

public static string ChoiceSelected="n"; 

public static int numberquestion=0; 

// Use this for initialization 
void Start() { 
    GetComponent<TextMesh>().text = questions [numberquestion]; 
} 

// Update is called once per frame 
void Update() 
{ 
    if (ChoiceSelected == "y") 
    { 


     if (CorrectAnswer [numberquestion] == SelectedAnswer) 
     { 
      Debug.Log("Correct"); 
      numberquestion++; 
      } 
     } 
    } 
} 

这是部numberquestion++,我需要改变,使其由一个增加。

+0

的代码是正确的...... – Gusman

+0

看起来像功课 – hardkoded

+1

什么是你的问题? –

回答

0

利用非静态变量在实例化时保存当前计数。这给一试:

public class TextControl : MonoBehaviour { 

    List<string> questions = new List<string>() {"When does time fly?","When does time?","When does?"}; 

    List<string> CorrectAnswer = new List<string>() {"3","3","3"}; 

    public static string SelectedAnswer; 

    public static string ChoiceSelected="n"; 

    public static int numberquestion=0; 

    public int myNumberQuestion; 

    // Use this for initialization 
    void Start() { 
    GetComponent<TextMesh>().text = questions [numberquestion]; 
    } 

    // Update is called once per frame 
    void Update() 
    { 
     if (ChoiceSelected == "y") 
    { 


    if (CorrectAnswer [numberquestion] == SelectedAnswer) 
    { 
     Debug.Log("Correct"); 
     myNumberQuestion = ++numberquestion; 
     } 
    } 
} 

}