Singleton code and Unify down.

Hi, I don’t really want to post this here however Unify is down. I was wondering if anyone had a link to an example or the code for singletons in Unity, component based or not.

I just don’t really want to wait for Unify to come back up before I can start working again. :stuck_out_tongue:

Thanks in advance, I usually search for this stuff before posting but cannot get to the information I need.

Edit: Let me rephrase my question because I thought there was a ‘one true singleton’ method

I am about to design a DisplayHUD Monobehavior in a multiplayer game, it displays several GUITextures on screen to give information about the player’s status. The multiplayer part of this is that when a spectator selects a given player to watch, their HUD should appear on the spectator’s screen as well, I already have it setup that the DisplayHUD script is synchronized across the network. (except with enemy players)

What I was thinking is to have a separate class inside the same file as DisplayHUD that is a ‘displayer’ Singleton. It chooses a single DisplayHUD Monobehavior instance as the target to display on the screen, and it’s local to the client. This is where I’m a bit stuck, I need the singleton to be accessable from our GUI script by just using Instance.getHUD but I don’t need it to be a lone component/GameObject.

Well, in Unity there are different singleton concepts (the usual one, or a component based).

Here’s an example of a component based singleton in C# or this one.