How to make initial global attributes?

Hi all.

First of all, sorry about my english… Im c# .net programmer, but totaly new in make games. I was using Stencyl for a while, but want to migrate to Unity.

I want to know a basic thing. How can I make to create global attributes for my game, and set initial values for them? And how to bind this global attributes script in the begining of the game?

Example:

I need some attributes to rule the game, like highscore, level, dificult, etc.

Can someone help me? thanks

You can put what you broadly call “initial attributes” into a number of different places in Unity3D, depending upon their intended scope and lifetime:

  • hard-coded into C# or JS code
  • editor prefab fields
  • editor scene object fields
  • listed in a text file (TextAsset) within the project

Something like a HighScore and/or difficulty setting would probably be best in a PlayerPrefs field. You can even give it an initial value if one has never been set before.

Each of the above places has advantages and disadvantages and may or may not be appropriate to the particular problem you are trying to solve. Experiment! Read the documentation, get a feel for how it all works.

1 Like

Typically you would have a GameObject in the scene whose purpose is simply to hold all of your manager scripts.

You can also use any of the techniques you would use in regular C# programming.

1 Like

So I have this class:
Singleton

And the inspector:
https://code.google.com/p/spacepuppy-unity-framework/source/browse/trunk/SpacepuppyBaseEditor/Inspectors/SingletonInspector.cs

The inspector creates a menu entry to create the GameObject singletons default being added to.

Next, any “manager” you inherit from the ‘Singleton’ class (instead of MonoBehaviour), then on the singleton manager object you’ll notice that their is a drop down that list all possible Singletons that are known. You can select any to add them to the gameobject.

1 Like

nice! thanks guys!

Maybe something like this?