unity don't destroy on load

Code Example - unity don't destroy on load

                
                        UnityEngine.Object.DontDestroyOnLoad(gameObject);
                    
                
 

unity dontdestroyonload

                        
                                private void Awake(){
	if(instance == null){
		instance = this;
    	DontDestroyOnLoad(instance);
	}
	else{
		Destroy(gameObject)
	}
}
                            
                        
 

Related code examples