Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matdombrock/unity-singleton
Dead simple unity singleton pattern implementation with no manager.
https://github.com/matdombrock/unity-singleton
Last synced: 7 days ago
JSON representation
Dead simple unity singleton pattern implementation with no manager.
- Host: GitHub
- URL: https://github.com/matdombrock/unity-singleton
- Owner: matdombrock
- License: mit
- Created: 2018-06-18T14:43:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-18T14:47:41.000Z (over 6 years ago)
- Last Synced: 2024-11-07T04:44:33.463Z (about 2 months ago)
- Language: C#
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity Simple Singleton
Dead simple unity singleton pattern implementation with no manager.Takes advantage of the way that unity loads objects to avoid needing a manager.
## Usage
Place this script on the object you want to be a singleton instance and give it a tag.
Implement said tag into the tag variable of this class.
## Code
```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Singleton : MonoBehaviour {
public string tag = "Music";
void Start () {
DontDestroyOnLoad (gameObject);
GameObject[] others = GameObject.FindGameObjectsWithTag (tag);
if (others.Length > 1) {
Destroy (gameObject);
}
}
}
```