加载场景不销毁物体
加载场景不销毁物体
挂在不想销毁的物体上
using UnityEngine;
public class DontDestroyObject : MonoBehaviour
{
    private static DontDestroyObject instance;
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }
}
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号