I need levels to unlock depending on how many collectibles have been gathered. However, the levels originally unlocked just by completing a level, now I would rather have them unlock only once you have collected a certain amount of balls. It still works as normal without taking into account the ballsUnlock variable.
Here is the code:
ballsUnlock is the public int I’ve set to allow me to manually input the amount of collectibles (balls) collected by the player.
I have highlighted the part which may be incorrect in Red.
Hope you can help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapPoint : MonoBehaviour
{
public MapPoint up, right, down, left;
public bool isLevel, isLocked;
public string levelToLoad, levelToCheck, levelName;
public int gemsCollected, totalGems, ballsUnlock;
public float bestTime, targetTime;
public GameObject gemBadge, timeBadge;
// Start is called before the first frame update
void Start()
{
if (isLevel && levelToLoad != null)
{
if (PlayerPrefs.HasKey(levelToLoad + “_gems”))
{
gemsCollected = PlayerPrefs.GetInt(levelToLoad + “_gems”);
}
if (PlayerPrefs.HasKey(levelToLoad + “_time”))
{
bestTime = PlayerPrefs.GetFloat(levelToLoad + “_time”);
}
if (gemsCollected >= totalGems)
{
gemBadge.SetActive(true);
}
if (bestTime <= targetTime && bestTime != 0)
{
timeBadge.SetActive(true);
}
isLocked = true;
if (levelToCheck != null)
{
if (PlayerPrefs.HasKey(levelToCheck + “_unlocked”))
{
if (PlayerPrefs.GetInt(levelToCheck + “_unlocked”) == 1)
{ if (gemsCollected >= ballsUnlock)
{
isLocked = false;
}
}
}
if (levelToLoad == levelToCheck)
{
{
isLocked = false;
}
}
}
// Update is called once per frame
void Update()
{
}
}
}
}
sorry guys, will tidy it up next time, I just slapped it on here without a second thought to be honest. The blue was facepalm worthy I admit - lol . Will tidy up the code a little more and see what I can come up with. Will get back to you, will be working on this today.