如何增加静态int数?

时间:2017-05-29 20:46:24

标签: c#

我不知道在得到正确答案时如何增加numberquestion。 如果你有能力,请告诉我如何在每次给出正确答案时numberquestion 1增加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++

我需要更改结束部分ION以使其增加1。

1 个答案:

答案 0 :(得分:0)

使用非静态变量来保存实例化时的当前计数。试一试:

class Block
{
  enum { type1, type2, type3 };
  int type;
  data Data;
public:
  Block(int x)
  : type(type1), Data(x) {}
  Block(std::string const& str)
  : type(type2), Data(str) {}
  Block(data const*x)
  : type(type3), Data(data) {}
  /* ... */
};

}