DontDestroyOnLoad(this.gameObject) will keep the the script alive when you load the next scene. But Unity will not magically guess that it shouldn't create another one when you come back to the original scene just because the one it created originally is still there.If you want a singleton object, you have to enforce that yourself. Otherwise all you will get is a bunch of duplicate objects, all trying to be the singleton. This is not the design pattern you are looking for.
Three ways I can think of:
- If you don't need an instance object in the scene (so that for example you could configure it in the inspector), you might just want a static class.
- You can keep a static instance variable. In Awake() check if the instance is null. If so, set it to this, and you are now the singleton instance: DontDestroyOnLoad(this.gameObject). If not, then you are not the chosen one: Destroy(this.gameObject).
- Have some other object be in charge of instantiating the singleton only if it doesn't already exist. Since it's never created automatically by Unity, you won't get duplicates. Unless you fuck it up and make them anyway.