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 rule62 · Feb 27, 2011 at 05:16 PM · beginnervariablesstoreconstant

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.

    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
    3
    Best Answer

    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; }

    Comment
    Add comment · Show 3 · 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 rule62 · Feb 27, 2011 at 07:14 PM 0
    Share

    Ah, thank you so much!

    avatar image The-BOOM · Feb 27, 2011 at 08:09 PM 0
    Share

    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.

    avatar image rule62 · Feb 27, 2011 at 09:42 PM 0
    Share

    ok. Good to know.

    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

    No one has followed this question yet.

    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


    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