유니티 C# DontDestroyOnLoad 간단 사용법

반응형
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);
        }
    }
}
반응형