I keep getting the error of index out of range exception for PlayerPrefsX Int Array. I want to replace the highscore whenever score is higher. Here are my codes:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score;
public static int[] highScores = new int[2];
public Text scoreText;
public Text highScoreText;
void Awake ()
{
score = 0;
if (PlayerPrefs.HasKey ("HighScore"))
highScores = PlayerPrefsX.GetIntArray ("HighScore");
PlayerPrefsX.SetIntArray ("HighScore", highScores);
}
void Update ()
{
if (Time.timeScale == 0)
{
scoreText.text = "Score: " + score;
highScoreText.text = "High Score: " + highScores [Application.loadedLevel - 1];
if (highScores [Application.loadedLevel - 1] > PlayerPrefsX.GetIntArray ("HighScore") [Application.loadedLevel - 1])
PlayerPrefsX.SetIntArray ("HighScore", highScores);
}
}
}
A function from another class:
void Score ()
{
if (count > ScoreManager.highScores [Application.loadedLevel - 1])
ScoreManager.highScores [Application.loadedLevel - 1] = count;
ScoreManager.score = count;
}