2 minute read

1. UI ๊ตฌํ˜„ํ•˜๊ธฐ

Hierarchy์—์„œ create -> UI -> Canvas๋ฅผ ๋งŒ๋“ ๋‹ค. UI์˜ Button์„ ์ƒ์„ฑํ•ด์ค€๋’ค Option Button์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. Panel์„ ์ƒ์„ฑํ•ด์ค€๋’ค Option์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ , Option์•„๋ž˜์— Button์„ 4๊ฐœ ๋งŒ๋“ ํ›„ ์ด๋ฆ„์„ ๊ฐ๊ฐ Play, Sound_On, Sound_Off, Menu๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. ์ด๋•Œ Sound ๋ฒ„ํŠผ ๋‘๊ฐœ๋Š” ์„œ๋กœ ๊ฒน์ณ ๋†“๋Š”๋‹ค. ์ดํ›„ ๋ฒ„ํŠผ๋ณ„ ์ž์‹ ์ด ์›ํ•˜๋Š” Asset์„ ๋„ฃ์–ด์ค€๋’ค, Panel์—๋Š” ์ ๋‹นํ•œ ์ƒ‰์ƒ์„ ๋„ฃ์–ด์ฃผ๊ณ , ํฌ๊ธฐ ์กฐ์ ˆ์„ ํ•œ๋‹ค.

๊ทธ๋Ÿฌ์ž ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌํ˜„๋˜์—ˆ๋‹ค.

image

์ดํ›„ Canvas์˜ ์ž์‹์œผ๋กœ UI_Manager๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ Empty ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ ํ›„ UI_Manager๋ผ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋„ฃ์–ด์ค€๋‹ค.

์Šคํฌ๋ฆฝํŠธ ์•ˆ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

public GameObject option_Button;
public GameObject option;
public GameObject sound_On;
public GameObject sound_Off;

public void Pause()
{
    option_Button.SetActive(false);
    option.SetActive(true);
}
public void Begin()
{
    option_Button.SetActive(true);
    option.SetActive(false);
}

public void Sound_On()
{
    sound_On.SetActive(false);
    sound_Off.SetActive(true);
}
public void Sound_Off()
{
    sound_On.SetActive(true);
    sound_Off.SetActive(false); 
}

public void MainMenu()
{

}

๊ฐ๊ฐ์— ๋ฒ„ํŠผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•จ์ˆ˜๋ฅผ ๋ฐฐ์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

playbutton

์ดํ›„ Sound_Off ์˜ค๋ธŒ์ ํŠธ์˜ inspector์— ์žˆ๋Š” ์ด๋ฆ„ ์˜†์˜ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ๋น„ํ™œ์„ฑํ™” ์‹œํ‚จ ํ›„์—, Option๋น„ํ™œ์„ฑํ™”๋ฅผ ์‹œํ‚ค๊ณ  ๊ฒŒ์ž„์„ ์ž‘๋™์‹œํ‚ฌ ์‹œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž˜ ์ž‘๋™๋œ๋‹ค.

option


2. MainMenu Scene ๋งŒ๋“ค๊ธฐ


๋‹ค์Œ์œผ๋กœ ์ด์ „๊นŒ์ง€ ๋งŒ๋“ค์—ˆ๋˜ Scene์„ ๋ณต์‚ฌํ•˜์—ฌ MainMenu๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. ์ดํ›„ ์•ˆ์— ์žˆ๋Š” GameManager๋ฅผ ์ œ์™ธํ•˜๊ณ  ๋‹ค ์ง€์›Œ์ค€๋‹ค.

์ดํ›„ ์ƒˆ๋กœ์šด Canvas๋ฅผ ๋งŒ๋“ ํ›„ MainMenu๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ Panel์„ ๋งŒ๋“ ๋‹ค. MainMenu์ด๋ฆ„์˜ Panel์˜ ์ž์‹์œผ๋กœ Text์™€ Button์„ ๋„ฃ์–ด์„œ ๊พธ๋ฉฐ์ค€๋‹ค. ๋‚˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ์„ฑํ•˜์˜€๋‹ค.

image

๋‹ค์Œ์œผ๋กœ Stage_List๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ Panel์„ ๋งŒ๋“ ํ›„ ๊ทธ ์ž์‹์œผ๋กœ Text์™€ Button`์„ ๋„ฃ์–ด์„œ ๊พธ๋ฉฐ์ค€๋‹ค. ์ดํ›„ ๋‚˜์˜จ ๊ฒฐ๊ณผ๋ฌผ์ด๋‹ค.

image


3. MainMenu ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ธฐ


์ง€๊ธˆ๊นŒ์ง€ MainMenu์˜ ์—ฌ๋Ÿฌ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ๋‹ค. ์ด์ œ ๊ทธ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฒ„ํŠผ๋“ค์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๊ธฐ๋Šฅ๋“ค์„ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
์ด๋ฅผ ์œ„ํ•˜์—ฌ MainMenu_UI_Manager์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŒ๋“ ํ›„ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

public class Bounce_MainMenu_UI_Manager : MonoBehaviour
{
    private GameObject Game_Manager;
    public GameObject MainMenu;
    public GameObject Stage_list;
    public GameObject Lock;

    // Start is called before the first frame update
    void Start()
    {
        Game_Manager = GameObject.FindGameObjectWithTag("GameManager");
        if (Game_Manager.GetComponent<Bounce_GameManager>().Is_Go_Stage_List == true)
        {
            Go_Stage_List();
        }
        Is_Lock();
    }

    // Update is called once per fram

    // ========================== Main Menu =========================
    public void Go_Stage_List()
    {
        MainMenu.SetActive(false);
        Stage_list.SetActive(true);
        Game_Manager.GetComponent<Bounce_GameManager>().Is_Go_Stage_List = true;
    }
        public void Show_Rank()
    {
        
    }

    public void End()
    {
        Application.Quit();

    }

    private void OnApplicationQuit()
    {
        Debug.Log("์ข…๋ฃŒ");
    }

    // ========================== Stage List =========================
    public void Go_MainMenu()
    {
        MainMenu.SetActive(true);
        Stage_list.SetActive(false);
        Game_Manager.GetComponent<Bounce_GameManager>().Is_Go_Stage_List = false;
    }
    public void Go_Stage(int Stage)
    {
        Game_Manager.GetComponent<Bounce_GameManager>().Current_Stage = Stage;
        SceneManager.LoadScene("Level " + Stage);
    }
    public void Is_Lock()
    {
        for (int i = 0; i <= Game_Manager.GetComponent<Bounce_GameManager>().Clear_Stage; i++)
        {
            Lock.transform.GetChild(i).gameObject.SetActive(false);
        }
    }
}

๊ฐ๊ฐ์˜ ๋ฒ„ํŠผ์— ์žˆ๋Š” On Click() Event ํ•จ์ˆ˜๋“ค์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค.
๋‹ค๋ฅธ Scene์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ๊ฐ๊ฐ์˜ Scene๋“ค์„ Buildํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
์ด๋ฅผ ์œ„ํ•ด ์ง€๊ธˆ๊นŒ์ง€ ๋งŒ๋“ค์–ด๋‘” testํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ Level 1์ด๋ผ๋Š” Scene์„ ๋งŒ๋“ค์–ด์ค€๋‹ค. ์ดํ›„ Level 1์„ ์ž์‹ ์ด ์›ํ•˜๋Š” ๋Œ€๋กœ ๊พธ๋ฏผ๋‹ค. ๋‹ค ๊พธ๋ฉด์œผ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด Build Setting์„ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

build



๊ฐœ์ธ ๊ณต๋ถ€ ๊ธฐ๋ก์šฉ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค.
ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ œ๋ณดํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.๐Ÿ˜