Answers for "unity dontdestroyonload"

C#
8

dontdestroyonload unity

DontDestroyOnLoad(this.gameObject);
Posted by: Guest on March-05-2020
7

dont destroy on load unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;// Object.DontDestroyOnLoad example.
//
// This script example manages the playing audio. The GameObject with the
// "music" tag is the BackgroundMusic GameObject. The AudioSource has the
// audio attached to the AudioClip.public class DontDestroy : MonoBehaviour
{
    void Awake()
    {
        GameObject[] objs = GameObject.FindGameObjectsWithTag("music");        if (objs.Length > 1)
        {
            Destroy(this.gameObject);
        }        DontDestroyOnLoad(this.gameObject);
    }
}
Posted by: Guest on June-03-2020
0

unity dontdestroyonload

private void Awake(){
	if(instance == null){
		instance = this;
    	DontDestroyOnLoad(instance);
	}
	else{
		Destroy(gameObject)
	}
}
Posted by: Guest on January-16-2021

C# Answers by Framework

Browse Popular Code Answers by Language