- Home /
Where to store a bunch of pre-set variables and constants? (noob question)
Hi,
I've got about 103 gazillion initialized variables, hashes, arrays and constants along with descriptive notes at the top of my "main" script. Is there something akin to a .h file I can put these away in?
If I put them in a separate script, do I need to then attach them to a gameObject?
If I put them into a separate script, will I have to
GetComponent("storageScript").somevariable
103 gazillion times from my actual functions script?
Thanks for any info.
EDIT:
Oops. Not answered. The suggested solution requires re-declaring variables in the main script anyway. Now I'm just duplicating all those variables.
Answer by The-BOOM · Feb 27, 2011 at 05:49 PM
You could do this:
//StorageScript.js
class MainVariables { var somethingOrOther : int; }
Save that in your standard assets, then when you need to access it:
//OtherScript.js
var variables = new MainVariables; var someVariable : int;
Update { someVariable = variables.somethingOrOther; }
You don't need to save StorageScript.js in your standard assets, but I will compile first when you're running your game, (or so I'm told) and that can avoid unnecessary run-time errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
FileStream/BinaryFormatter save static variables without PlayerPrefs 1 Answer
Using string to refer to variable 2 Answers
Sorting variable names by their values. 2 Answers
General question/advice for displaying multiple variables on a gameobject 0 Answers
Do i need to create a "current value" for those private variables? 0 Answers