1. 현재 스테이지(또는 난도)에 따라 카드 배열 증가시켜보기

    1. 발견된 문제 : 다른 Scene에서 난이도 변수가 결정되고 MainScene으로 넘어와서 게임이 실행되는 구조라 데이터가 다른 Scene으로 넘어오지 못하는 문제가 발생함.
    2. 문제 해결 : 데이터를 가져와도 값을 가져오지 못해서 생기는 문제로 해당 변수와 난이도 설정 함수를 모두 static으로 선언하였으며, 정상적으로 작동하는 것을 볼 수 있었음.
    difficulty.cs
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class difficulty : MonoBehaviour
    {
        // Start is called before the first frame update
        public static int difficulty_level = 1;
    
        public static void easy()
        {
            difficulty_level = 0;
            SceneManager.LoadScene("MainScene");
        }
    
        public static void normal()
        {
            difficulty_level = 1;
            SceneManager.LoadScene("MainScene");
        }
    
        public static void hard()
        {
            difficulty_level = 2;
            SceneManager.LoadScene("MainScene");
        }
    }
    
    if (difficulty.difficulty_level == 0)
    {
        int[] cards = { 0, 0, 1, 1, 2, 2, 3, 3};
        string cardName;
    
        cards = SuhffleArray(cards);
        float x;
        float y;
        for (int i = 0; i < 8; i++)
        {
            GameObject newCard = Instantiate(card);
            newCard.transform.parent = GameObject.Find("cards").transform;
    
            x = (i / 2) * 1.4f - 2.1f;
            y = (i % 2) * 1.4f - 2.0f;
            newCard.transform.position = new Vector3(x, y, 0);
    
            cardName = cards[i].ToString();
            newCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(cardName);
        }
    }
    else if(difficulty.difficulty_level == 1)
    {
        int[] cards = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
        string cardName;
    
        cards = SuhffleArray(cards);
        float x;
        float y;
        for (int i = 0; i < 12; i++)
        {
            GameObject newCard = Instantiate(card);
            newCard.transform.parent = GameObject.Find("cards").transform;
    
            x = (i / 3) * 1.4f - 2.1f;
            y = (i % 3) * 1.4f - 2.0f;
            newCard.transform.position = new Vector3(x, y, 0);
    
            cardName = cards[i].ToString();
            newCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(cardName);
        }
    }
    else if(difficulty.difficulty_level == 2)
    {
        int[] cards = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,6,6,7,7 };
        string cardName;
    
        cards = SuhffleArray(cards);
        float x;
        float y;
        for (int i = 0; i < 16; i++)
        {
            GameObject newCard = Instantiate(card);
            newCard.transform.parent = GameObject.Find("cards").transform;
    
            x = (i / 4) * 1.4f - 2.1f;
            y = (i % 4) * 1.4f - 3.4f;
            newCard.transform.position = new Vector3(x, y, 0);
    
            cardName = cards[i].ToString();
            newCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(cardName);
        }
    }
    
  2. 결과에 점수 표시 → 남은 시간, 매칭 시도한 횟수 등을 점수로 환산

    1. endText를 변환하는 것으로 구현 시도
    2. endBtn을 만들고 count, time, score를 모두 endBtn 내에 들어가도록 함
    3. 점수 변환 식 : 남은 시간*10 - 시도 횟수
    4. 시간이 30초 지나서 끝나면 점수는 0점으로 함
    public Text countText;
    public Text scoreText;
    public Text losetimeText;
    
    if (time > 30.0f)
    {
        float losetime = 30.0f - time;
        int score = 0;
        losetime = 0.0f;
    
        Debug.Log(score);
        Debug.Log(losetime);
        countText.text = counter.ToString();
        losetimeText.text = losetime.ToString("N2");
        scoreText.text = score.ToString();
        endBtn.SetActive(true);
        Time.timeScale = 0.0f;
    }
    
    {
        float losetime = 30.0f - time;
        int score;
        score = Convert.ToInt32(losetime * 10 - counter);
        Debug.Log(score);
        Debug.Log(losetime);
        countText.text = counter.ToString();
        losetimeText.text = losetime.ToString("N2");
        scoreText.text = score.ToString();
        endBtn.SetActive(true) ;
        Time.timeScale = 0.0f;
    }
    
  3. 스테이지 선택과 현재 해금한 스테이지가 구분 가능한 시작 화면 만들기, 플레이 중 해당 스테이지의 최단 기록 띄워주기

    1. 미리 만들어 놓은 StartScene을 시작 화면으로 만들고 해당 화면에서 난이도 별 스테이지 선택을 할 수 있음
    2. 스테이지 해금 기능을 추가하기 위해서는 이전 난이도를 클리어 했다는 조건이 있어야 다음 난이도를 선택했을 때 그 난이도가 실행 되도록 조건을 만들어야 함
    3. 스테이지 별 최단 기록을 띄우는 것은 난이도 별로 플레이 시 스코어를 저장하여 저장된 스코어가 현재 스코어 보다 낮으면 새로 스코어를 저장하는 방식으로 최고 기록을 띄우도록 함
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class difficulty : MonoBehaviour
    {
        // Start is called before the first frame update
        public static int difficulty_level = 1;
        public GameObject isClear;
    
        public void easy()
        {
            difficulty_level = 0;
            SceneManager.LoadScene("MainScene");
        }
    
        public void normal()
        {
            if(PlayerPrefs.HasKey("easybestScore") == true)//이지 난이도 클리어기록 확인
            {
                difficulty_level = 1;
                SceneManager.LoadScene("MainScene");
            }
            else
            {
                isClear.SetActive(true);
            }
        }
    
        public void hard()
        {
            if(PlayerPrefs.HasKey("normalbestScore") == true)//노말 난이도 클리어기록 확인
            {
                difficulty_level = 2;
                SceneManager.LoadScene("MainScene");
            }
            else
            {
                isClear.SetActive(true);
            }
        }
    
        public void Reset()//기록을 리셋
        {
            PlayerPrefs.DeleteAll();
        }
    }
    
    if(difficulty.difficulty_level == 0)
    {
        if (PlayerPrefs.HasKey("easybestScore") == true)
        {
            if(PlayerPrefs.GetInt("easybestScore") < score)
            {
                PlayerPrefs.SetInt("easybestScore", score);
            }
        }
        else
        {
            PlayerPrefs.SetInt("easybestScore", score);
        }
        bestText.text = PlayerPrefs.GetInt("easybestScore").ToString();
    }
    else if (difficulty.difficulty_level == 1)
    {
        if (PlayerPrefs.HasKey("normalbestScore") == true)
        {
            if (PlayerPrefs.GetInt("normalbestScore") < score)
            {
                PlayerPrefs.SetInt("normalbestScore", score);
            }
        }
        else
        {
            PlayerPrefs.SetInt("normalbestScore", score);
        }
        bestText.text = PlayerPrefs.GetInt("normalbestScore").ToString();
    }
    else if (difficulty.difficulty_level == 2)
    {
        if (PlayerPrefs.HasKey("hardbestScore") == true)
        {
            if (PlayerPrefs.GetInt("hardbestScore") < score)
            {
                PlayerPrefs.SetInt("hardbestScore", score);
            }
        }
        else
        {
            PlayerPrefs.SetInt("hardbestScore", score);
        }
        bestText.text = PlayerPrefs.GetInt("hardbestScore").ToString();
    }