간단하게 게임을 플레이한 영상

간단하게 게임을 플레이한 영상

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class StageManager : MonoBehaviour
{
    public int kill_count;
    public int enemy_count;
    public int this_stage = 0;
    public int next_stage = 0;
    public int stage_level;

    public List<string> scenes = new List<string>();

    private void Awake()
    {
        DontDestroyOnLoad(gameObject);
        stage_level = 100;
        init();
    }

    public bool isClear()
    {
        if(kill_count < enemy_count)
        {
            return false;
        }
        else
        {
            kill_count = 0;
            enemy_count = 0;
            return true;
        }
    }

    private void init()
    {
        scenes.Clear();
        scenes.Add("Scene1");
        scenes.Add("Scene2");
        scenes.Add("Scene3");
        scenes.Add("Scene4");
    }

    public void kill()
    {
        kill_count++;
        if (isClear())
        {
            Clear();
        }
    }

    public void Clear()
    {
        Debug.Log("Stage Clear!");
        next_stage = Random.Range(0, 4);
        if (this_stage != next_stage)
        {
            stage_level += 10;
            this_stage = next_stage;
            LoadingSceneManager.LoadScene(scenes[next_stage]);
        }
        else
        {
            Clear();
        }
        
    }

    public void GameOver()
    {
        LoadingSceneManager.LoadScene("GameOver");
    }

    public void GameStart()
    {
        LoadingSceneManager.LoadScene(scenes[0]);
    }
}

<aside> ⚠️ 유저가 몬스터 하나를 잡을 때마다 킬 카운터를 올리고, 스테이지 생성 시 생성되는 몬스터의 숫자를 기억해놓았다가 킬 카운터가 그 수와 같아지면 스테이지 클리어 판정

</aside>

로딩씬 만들기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LoadingSceneManager : MonoBehaviour
{
    public static string nextScene;
    [SerializeField]
    Image progressBar;

    private void Start()
    {
        progressBar.fillAmount = 0;
        StartCoroutine(LoadScene());
    }

    public static void LoadScene(string sceneName)
    {
        nextScene = sceneName;
        SceneManager.LoadScene("LoadingScene");
    }

    IEnumerator LoadScene()
    {
        yield return null;
        AsyncOperation op = SceneManager.LoadSceneAsync(nextScene);
        op.allowSceneActivation = false;
        float timer = 0.0f;
        while(!op.isDone)
        {
            yield return null;
            timer += Time.deltaTime / 5f;
            if (op.progress < 0.9f)
            {
                progressBar.fillAmount = Mathf.Lerp(progressBar.fillAmount, op.progress, timer);
                if(progressBar.fillAmount >= op.progress)
                {
                    timer = 0f;
                }
            }
            else
            {
                progressBar.fillAmount = Mathf.Lerp(progressBar.fillAmount, 1f, timer);
                if(progressBar.fillAmount == 1.0f)
                {
                    op.allowSceneActivation = true;
                    yield break;
                }
            }
        }
    }
}

<aside> ⚠️ 씬이 넘어가면서 씬을 불러오는 시간 동안 VR기기가 같이 멈추는 현상이 있다. VR의 경우 유저의 편의성도 많이 고려해야하기 때문에 로딩 씬을 필수적으로 넣어야겠다고 생각했다. 그래서 로딩 씬을 구현해보았다.

</aside>