I want to manage HighScore levelwise…For that I am using PlayerPrefs plugin.
I have written below code to manage highscore:
ScoreController Script in JS:
public var highScoreList : List.<int> = new List.<int>();
function Start () {
LoadData();
gameControllerScript = GameObject.Find("Main Camera").GetComponent("GameController");
}
function LoadData()
{
for (var i : int = 0; i < highScoreList.Count; i++)
{
highScoreList *= PreviewLabs.PlayerPrefs.GetInt("highScore" + i);*
}
}
function Update () {
if (!once)
{
-
if(GameController.Score >= gameControllerScript.objectiveScore)* -
{* -
if(GameController.HighScore < GameController.Score)* -
{* -
highScoreList[GameController.level] = GameController.Score; // Error Comes From Here* -
Debug.Log("new high score: " + GameController.Score);*
SaveData();
-
}*
once = true;
-
}*
}
}
function SaveData()
{
for (var i : int = 0; i < highScoreList.Count; i++)
{
PreviewLabs.PlayerPrefs.SetInt(“highScore” + i,highScoreList*);*
}
PreviewLabs.PlayerPrefs.Flush();
}
But it gives me ArgumentOutOf range Exception…
So how do i store and update my highscore for perticuler level?
Consol :
Argument is out of range.
Parameter name: index
_System.Collections.Generic.List1[System.Int32].CheckIndex (Int32 index)*_ <em>*System.Collections.Generic.List1[System.Int32].set_Item (Int32 index, Int32 value)
Pleaze Help me…
Thanx for your Support and Help…
Please copy the error message from your Console and post it here. Also add a comment to the code above on the line that is generating the IndexOutOfRange Exception. Note you have not included the code that initializes 'higheScoreList' above.
– robertbuoops.. sorry sir. its argumentoutofrange..
– Ekta-Mehta-DUse [ArrayPrefs2][1] to save arrays using PlayerPrefs. [1]: http://wiki.unity3d.com/index.php?title=ArrayPrefs2
– Eric5h5@Eric5h5 But What is the problem with this script?? and sir can you plese show me the way of using ArrayPrefs2??
– Ekta-Mehta-DThe page I linked to has instructions; read them. I posted that as a comment instead of an answer because if you use ArrayPrefs2, you don't need that script at all.
– Eric5h5