2016-04-29 18 views
0

ファイルをロードして作成するためのストリームリーダとストリームライタを作成しました。しかし、新しいものが達成されたときに高い得点を更新するために、上位5つの高い得点のリストを反復することに問題がある。ハイスコアをテキストファイルに保存する方法

 public int highscore; 
    public static int score; 
    //public new string name; 
    private string initials; 
    public List<int> highscores; 
    //public List<Person> highscores; 
    Text HighScoreText; 

    void Awake() 
    { 
     HighScoreText = GetComponent<Text>(); 
     score = 0; 
     highscores = new List<int>(); 
     score = PlayerPrefs.GetInt("Score",0); 
     highscore = PlayerPrefs.GetInt("HighScore", 0); ; 
     LoadScore(); 
     UpdateScore(); 

    } 
    void UpdateScore() 
    { 


     HighScoreText.text = "HighScore:" + score; 
//Here I get an error cannot apply indexing with type int 
     if (score > highscores[4].s) 
     { 
      highscores.Add(score); 
      highscores.Sort(); 

      highscore = score; 
      HighScoreText.text = highscore.ToString(); ; 
     } 

    } 
+0

あなたは 'if(score> highscores [4]){'を意味しましたか?最後の '.s'は意味をなさない。新しいハイスコアを追加する場合は、6番目/最下位を削除することを忘れないでください! – Mephy

答えて

0

あなたはintlistとしてhighscoresを宣言:public List<int> highscores;

を次にあなたがのために.sあるものif (score > highscores[4].s) { ... }をチェックしていますか?あなたはまったくそれを必要としません。 if (score > highscores[4])をチェックするだけで、あなたのコードは正常にコンパイルされます。

また、コンパイルした後で、コードステートメントごとにデバッグしてロジックをチェックしたいとします。 Visual Studioを使用している場合は、F-10 step-overオプションを使用します。

関連する問題