I'm trying to store value of an INT scoreValue that is in scrip "SCORE" in Unity game.
as for every level it will be different value, at the moment I'm doing separate function LEVEL1(), LEVEL2() etc. and store that value in layerPrefs.SetInt("scoreLVL1", Score.scoreValue); & layerPrefs.SetInt("scoreLVL2", Score.scoreValue); etc. etc.
but If I'm planning to have 100 levels, I would need to do 100 functions.
Is there simpler way to store all the values of each level in one function ?
I'm a beginner in Unity and at the moment can't get my head around it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public string nextLevel = "Level02";
public int levelToUnlock = 2;
public sceneFade sceneFader;
public PauseScript pauseresume;
public void level1()
{
pauseresume.levelCompletedmenu();
if (PlayerPrefs.GetInt("levelReached") < levelToUnlock)
{
PlayerPrefs.SetInt("levelReached", levelToUnlock);
}
PlayerPrefs.SetInt("scoreLVL1", Score.scoreValue);
PlayerPrefs.Save();
}
public void level2()
{
pauseresume.levelCompletedmenu();
if (PlayerPrefs.GetInt("levelReached") < levelToUnlock)
{
PlayerPrefs.SetInt("levelReached", levelToUnlock);
}
PlayerPrefs.SetInt("scoreLVL2", Score.scoreValue);
PlayerPrefs.Save();
}
}