Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Muuskii · Jul 27, 2012 at 10:28 PM · c#componentsingleton

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. :P

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jul 27, 2012 at 10:31 PM

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

http://search.unity3d.com/uss1/?q=singleton&type_of_search=answers

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Muuskii · Jul 27, 2012 at 11:11 PM 0
Share

Noted, I'll rephrase my question.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Null Reference Exception on instantiated object's script. 2 Answers

Multi similar script Components same game object 1 Answer

C# How to Check If a Gameobject Contains a Certain Component 6 Answers

Classes and Scripting 2 Answers

Singleton that can react to game events 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges