Skip to content

Instantly share code, notes, and snippets.

@yuseinishiyama
Created January 17, 2014 02:42
Show Gist options
  • Save yuseinishiyama/8467576 to your computer and use it in GitHub Desktop.
Save yuseinishiyama/8467576 to your computer and use it in GitHub Desktop.
Attaching this script to a object, the object survives in all scenes. (For Unity3d)
using UnityEngine;
using System.Collections;
public class DontDestroyObject : MonoBehaviour
{
static DontDestroyObject instance;
void Awake ()
{
if (!instance) {
instance = this;
DontDestroyOnLoad (gameObject);
} else {
Destroy (gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment