Skip to content

Instantly share code, notes, and snippets.

@Dssdiego
Last active April 22, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dssdiego/9126e6d3a9a6da9576afd69c25b4ee8b to your computer and use it in GitHub Desktop.
Save Dssdiego/9126e6d3a9a6da9576afd69c25b4ee8b to your computer and use it in GitHub Desktop.
Unity Singleton Pattern
using System;
using UnityEngine;
public class MyScript : MonoBehaviour
{
public static MyScript Instance { get; private set; }
private void Awake()
{
if (Instance != null)
{
Destroy(this);
}
else
{
Instance = this;
}
DontDestroyOnLoad(Instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment