Imagine a map has more than one path, one level unlocks multiple levels that are on separate paths. And after they completed, each level unlocks the next level on their own paths. Can anyone help =) I found tutorials about how to unlock the next level. The problem is they created as to unlock the current and all the levels before them. Because of my level map is not a single linear system, those won’t work for me.
Think of your level unlocks as unlock ranges. Range 0 unlocks 1-5, Range 1 unlocks 6-10 and so on:
using UnityEngine;
public class LevelUnlocking : MonoBehaviour
{
// Define your own ranges here. Add more as you like.
int[][] unlockRanges =
{
new [] {1, 2, 3, 4, 5},
new [] {6, 7, 8, 9, 10}
};
void Start()
{
SetLevelButtonInteractable();
}
void SetLevelButtonInteractable()
{
for (int i = 0; i < unlockRanges.Length; i++)
{
string key = "RangeReached" + i;
bool rangeReached = PlayerPrefs.GetInt(key, 0) == 1;
if (rangeReached)
{
for (int j = 0; j < unlockRanges*.Length; j++)*
{
int level = unlockRanges*[j];*
// Make sure lvlButtons is defined for you.
lvlButtons[level].interactable = true;
}
}
}
}
}