1 분 소요

-SceneControlmng-

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

public class SceneControlmng : MonoBehaviour
{

    static SceneControlmng _unique;
    
    public enum eLoaddingState
    {
        none               = 0,
        start,
        ing,
        end
    }

    AsyncOperation _loadProc;
    eLoaddingState _noewLoadState = eLoaddingState.none;
    static public SceneControlmng _instance
    {
        get { return _unique; }   
    }

    void Awake()
    {
        _unique= this;
        DontDestroyOnLoad(gameObject);
        StartTitle();
    }

    void LateUpdate()
    {
        if (_loadProc != null)
        {
            if (_loadProc.isDone)
            {
                _noewLoadState = eLoaddingState.ing;
                // 로딩 바 계산.
                //_loadProc.progress;
                return;
            }
            else
            {
                _loadProc = null;

                _noewLoadState = eLoaddingState.end;
            }
        }
    }

    public void StartTitle()
    {
        _noewLoadState = eLoaddingState.start;
        _loadProc = SceneManager.LoadSceneAsync("TitleScene");
    }

    public void StartIngame()
    {
        _noewLoadState = eLoaddingState.start;
        _loadProc = SceneManager.LoadSceneAsync("IngameScene");
    }

}

-TitleManger-

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

public class TitleManager : MonoBehaviour
{
    public Text _txtPush;
    float _tickTime = 0;
    SceneControlmng _mngScene;  


     void Start()
    {
        GameObject go = GameObject.Find("SceneControlManager");
    }

    void Update()
    {
        _tickTime += Time.deltaTime;
        if(_tickTime >= 0.3f)
        {
            _tickTime = 0;
            _txtPush.gameObject.SetActive(!_txtPush.gameObject.activeSelf);
        }

        if (Input.GetButtonDown("Fire1"))
        {
            SceneControlmng._instance.StartIngame();
        }
    }
}

-IngameManager

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

public class IngameManager : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Cancel"))
        {
            SceneControlmng._instance.StartTitle();
            
        }
    }
}
  • Tilte Scene 씬 만들고, canvas에 titlemanager 스크립트 추가
  • StartScene씬 만들고, SceneControlMager 만들기 Scene Controllmng 스크립트 추가
  • IngameScene에서 sort lay out 추가..(mainbg, middle, far, near, player 등..)

댓글남기기