Hello,
I made a game with 100 levels and when i’m on level (for example) 80 and I finish it.
I close the game and When i’m going back to MenuScene, the game is on Level 1… and i have to scroll to level 80…
Anyone have an idea to save this ? (I have an Level.Json, to store all data level)
Here is my code :
void Start()
{
//Get Level data
data = null;
string path = JSON_PATH;
TextAsset textAsset = Resources.Load<TextAsset>(path);
data = textAsset.ToString().Split(';');
//Get Level Data solved
string[] levelSolvedData = PlayerPrefs.GetString(LevelManager.LEVELSOLVED_KEY).Split('_');
int highestLevelSolved;
//Find the highest level solved
if (levelSolvedData.Length == 1)
{
highestLevelSolved = 0;
}
else
{
highestLevelSolved = int.Parse(levelSolvedData[0].Trim());
for (int i = 1; i < levelSolvedData.Length; i++)
{
if (highestLevelSolved < int.Parse(levelSolvedData[i]))
{
highestLevelSolved = int.Parse(levelSolvedData[i]);
}
}
}
//Find all levels resolved in the pack
float range = highestLevelSolved / LEVELS_PER_PACK;
List<int> listLevelSolvedInRange = new List<int>();
if (highestLevelSolved != 0)
{
foreach (string o in levelSolvedData)
{
if (range > 0)
{
if (int.Parse(o) >= range * LEVELS_PER_PACK && int.Parse(o) <= (range + 1) * LEVELS_PER_PACK)
{
listLevelSolvedInRange.Add(int.Parse(o));
}
}
else
{
listLevelSolvedInRange.Add(int.Parse(o));
}
}
}
//Prepare scrollview level details
#region Handle Level Detail Scrollview
//Calculate the level group
float levelgroupNumber = Mathf.Ceil(data.Length / (float)buttonGroupPrefab.transform.childCount);
ScrollToSelectedPack();
int count = 0;
//Generate the level group each level group at 20 levels
for (int i = 1; i <= levelgroupNumber; i++)
{
GameObject buttonGroup = Instantiate(buttonGroupPrefab, levelDetailContent.transform.position, Quaternion.identity) as GameObject;
buttonGroup.transform.SetParent(levelDetailContent.transform);
buttonGroup.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
int childCount = 0;
for (int j = count; j < buttonGroup.transform.childCount * i; j++)
{
if (j >= data.Length)
{
buttonGroup.transform.GetChild(childCount).gameObject.SetActive(false);
}
else
{
LevelData levelData = JsonUtility.FromJson<LevelData>(data[j]);
Transform theChild = buttonGroup.transform.GetChild(childCount);
theChild.GetComponentInChildren<Text>().text = levelData.levelNumber.ToString();
LevelButtonController levelButtonController = theChild.GetComponent<LevelButtonController>();
GameObject lockOb = theChild.Find("Lock").gameObject;
GameObject imgSolvedOb = theChild.Find("imgSolved").gameObject;
Image levelImg = theChild.Find("Mask").Find("Image").GetComponent<Image>();
RectTransform levelImgRT = levelImg.GetComponent<RectTransform>();
I hope anyone can help me with that…
If anyone have an idea but he had to look deeper in my code, we can go on chat (Skype or something else)
Thanks for your time and help.
Best regards,
Shinsuki