- Home /
This post is currently awaiting moderation. If you believe this to be in error, contact a system administrator.
Question by
tommynanny · Aug 24, 2018 at 07:51 AM ·
c#script.scripting beginnersingleton
Singleton implementation
I used to have my Singleton(GameManager, SoundManager...) attached to sperate game objects. I was wondering if I can have them attached to one and only one game object instead. And only wrote "DontDestroyOnLoad" in one of the Singleton.
Comment
Answer by Casiell · Aug 24, 2018 at 08:28 AM
As far as I know you can't do that. You can tho destroy each but one instance of the script it it happens to be on the scene.
public static T Instance;
private void Awake()
{
if(Instance == null
Instance = this;
else
Destroy(this);
}
Your answer
Follow this Question
Related Questions
Why when using get; set; in one script i'm getting null in other script that use it ? 1 Answer
Help me with this code proplem,,Almost finish my game please help this once 3 Answers
Script executing through walls 1 Answer
I made Infinite jump Fix Script By Myself But I Want You Guys To Take Look at My Script... 0 Answers