**PlayerPrefs**를 이용하여 난이도 Lock, UnLock를 구현했습니다.


난이도 설계

UI 설계

Untitled

Untitled

다음에 Difficulty UI를 Lock 컨셉과 일치하도록 수정한 뒤, Normal, Hard Button의 Interactable를 False로 설정했다.

스크립트 작성

MainScene이 시작될 때마다 해금된 난이도 정보를 불러오고 해금하는 기능을 가진 UnLock스크립트를 만들고 StartUI에 붙혀줬다.

using UnityEngine;
using UnityEngine.UI;

public class UnLock : MonoBehaviour
{
    private DifficultyManager dif;
    
    [Header("# Object")]
    // 0번 : Normal버튼, 1번 : Hard버튼
    [SerializeField] private Button[] difficultyBtns;
    // 난이도 잠김 표시 오브젝트
    [SerializeField] private GameObject[] touchBlocks;
    
    private void Awake()
    {
        dif = DifficultyManager.instance;
    }

    private void Start()
    {
        // 난이도 해금 0: easy, 1: normal, 2: Hard
        dif.unLockDifficulty = PlayerPrefs.GetInt("Difficulty_Info");
        // 1일 때 => normal 해금, 2일 떄 => Hard 해금
        for (int i = 1; i < dif.unLockDifficulty + 1; i++)
        {
            // normal과 Hard는 0,1 번째에 들어가 있기 때문에 -1 해서 접근함
            difficultyBtns[i - 1].interactable = true;
            touchBlocks[i - 1].SetActive(false); // 난이도 잠금 표시 해제
        }
    }
}

해당 난이도를 처음 클리어 했을 땐 난이도 해금 정보를 업데이트 해줬다.

using UnityEngine;

public enum Difficulty {Default, Easy, Normal, Hard}

public class DifficultyManager : MonoBehaviour
{
    public static DifficultyManager instance;
    
    [Header("# Game Difficulty Information")]
    // 게임의 난이도
    public Difficulty difficulty;
    // 지금까지 언락된 난이도 Normal : 1
    [HideInInspector]public int unLockDifficulty;
    private void Awake()
    {
        /* 싱글톤*/
    }

    // Easy나 Normal을 처음 클리어 했을 경우 실행되는 함수
    public void UnLock()
    {
        // 현재 언락된 난이도가 현재 진행중인 게임의 난이도이고 언락된 난이도가 이지, 노말일 때
        if (unLockDifficulty == (int)difficulty - 1 && unLockDifficulty < 2)
        {
            // 난이도 데이터 저장 (이지 -> 노말) (노말 -> 하드)
            PlayerPrefs.SetInt("Difficulty_Info",++unLockDifficulty );
        }
        
    } 
}

구현