I'm having an issue right now while trying to follow a course for Unity. The course goes through the code that is currently outdated and I have a more recent version of it. The issue is as followed: I need to make a playerpref for unlocking new levels in the game and I am being instructed to use :
if (level <= Application.levelCount - 1)
{
return isLevelUnlocked;}
since this is obsolete, I'm not sure what to use in place of it... I saw some people suggest to use the scenemanagment, but I can't get it to work... here is the full coded:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerPrefsManager : MonoBehaviour
{
const string MASTER_VOLUME_KEY = "master_volume";
const string DIFFICULTY_KEY = "difficulty";
const string LEVEL_KEY = "level_unlocked_";
public static void SetMasterVolume(float volume)
{
if (volume > 0f && volume < 1f)
{
PlayerPrefs.SetFloat(MASTER_VOLUME_KEY, volume);
}
else
{
Debug.LogError(" Master volume out of range");
}
}
public static float GetMasterVolume()
{
return PlayerPrefs.GetFloat(MASTER_VOLUME_KEY);
}
public static void UnlockLevel(int level)
{
if (level <= Application.levelCount - 1)
{
PlayerPrefs.SetInt(LEVEL_KEY + level.ToString(), 1);
}
else
{
Debug.LogError("trying to unlock level not in build order");
}
}
public static bool IsLevelUnlocked(int level)
{
int levelValue = PlayerPrefs.GetInt(LEVEL_KEY + LEVEL_KEY.ToString());
bool isLevelUnlocked = (levelValue == 1);
{
if (level <= Application.levelCount - 1)
{
return isLevelUnlocked;
}
else
{
Debug.LogError("trying to query level not in build order");
return false;
}
}
}
public static void SetDifficulty(float difficulty)
{
if (difficulty >= 0f && difficulty <= 1f)
{
PlayerPrefs.SetFloat(DIFFICULTY_KEY, difficulty);
}
else
{
Debug.LogError("difficulty out of range");
}
}
public static float GetDiffculty()
{
return PlayerPrefs.GetFloat(DIFFICULTY_KEY);
}
}
with the course, I test it using PlayerPrefsManager.UnlockLevel(2); , but it wont work because the damn thing is outdated and I haven't the foggiest on how to compensate for it... any clues?