- Home /
How to define component properties globally
Hi,
Let's say I have a component that has some properties, like some mouse cursor icon and some icons, and I plan to create several scenes with the same component with the same property values attached to each main camera.
How could I define these values just once globally and reuse (share) that configuration across all instances of the component in all scenes?
I envision I will have to create some custom Editor window to allow the designer to define these values. But I need to know if it possible to store the resource references somewhere and link all component instances to this.
Thanks in advance for any help.
Answer by proandrius · May 03, 2013 at 12:23 AM
MyGlobalVariables.cs
public static int myVar = 0;
public static void UpdateVar(int newVar)
{
myVar = newVar;
}
And you don't need to assign this script anywhere and you can access it from anywhere by writing MyGlobalVariables.UpdateVar(5);
As far as I can tell, static properties can only be set programmatically. I'm still missing here how can I let the designer specify these in a custom editor window and make these available at run time.
$$anonymous$$ake Editor script which changes these values. Or assign it to the GameObject and add make script to that object:
function Awake () {
DontDestroyOnLoad (this.gameObject);
}
Your answer led me to this other answer: http://answers.unity3d.com/questions/39717/static-variables-assigned-in-the-inspector.html
I ended up putting all the properties in a prefab with a script, and an accessor property to statically reach out to those properties from any other classes.
Thanks for the help.
BTW, I just read your blog http://www.canonepersonmakerpg.com and I found out that we're both undertaking the same type of project, except that $$anonymous$$e is an adventure game ins$$anonymous$$d of an RPG. Best of luck with your entreprise! If you wish to take a look, I'm blogging my progress here: http://anadventuregame.blogspot.com
Cheers