Zymus
3
Q:

dont destroy on load unity

        DontDestroyOnLoad(this.gameObject);
7
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);
    }
}
6
 private static Player playerInstance; 

void Awake(){     
	 DontDestroyOnLoad (this);
	 
  if (playerInstance == null) {         
 	playerInstance = this;     
	 } 
  else {
 	DestroyObject(gameObject);
 	} 
 }
0

New to Communities?

Join the community