-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathSingletonStructure.cs
More file actions
40 lines (34 loc) · 857 Bytes
/
SingletonStructure.cs
File metadata and controls
40 lines (34 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//-------------------------------------------------------------------------------------
// SingletonStructure.cs
//-------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SingletonStructure : MonoBehaviour
{
void Start()
{
var s1 = Singleton.Instance;
var s2 = Singleton.Instance;
if (s1 == s2)
{
Debug.Log("Objects are the same instance");
}
}
}
public class Singleton
{
private static Singleton _instance;
protected Singleton() { }
public static Singleton Instance
{
get
{
if (_instance == null)
{
_instance = new Singleton();
}
return _instance;
}
}
}