본문 바로가기
개발/C#

유니티 C# DontDestroyOnLoad 간단 사용법

by SPNK 2022. 6. 19.
반응형
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleDontDestroyOnLoad : MonoBehaviour
{
    void Awake()
    {
        var obj = FindObjectsOfType<ExampleDontDestroyOnLoad>();
        if (obj.Length == 1)
        {
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(this);
        }
    }
}
반응형

댓글